Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/style/XStyle.hpp>
31 : : #include <com/sun/star/lang/XServiceInfo.hpp>
32 : : #include <com/sun/star/lang/XComponent.hpp>
33 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
34 : : #include <com/sun/star/container/XIndexAccess.hpp>
35 : : #include <com/sun/star/container/XNameContainer.hpp>
36 : : #include <com/sun/star/beans/XPropertySet.hpp>
37 : : #include <com/sun/star/util/XModifyBroadcaster.hpp>
38 : : #include <com/sun/star/util/XModifyListener.hpp>
39 : : #include <comphelper/serviceinfohelper.hxx>
40 : :
41 : : #include <osl/mutex.hxx>
42 : : #include <vcl/svapp.hxx>
43 : :
44 : : #include <cppuhelper/basemutex.hxx>
45 : : #include <cppuhelper/compbase6.hxx>
46 : : #include <cppuhelper/implbase7.hxx>
47 : : #include <cppuhelper/interfacecontainer.h>
48 : :
49 : : #include "svx/unoprov.hxx"
50 : : #include "svx/sdr/table/tabledesign.hxx"
51 : : #include "svx/dialmgr.hxx"
52 : : #include "svx/dialogs.hrc"
53 : :
54 : : #include "celltypes.hxx"
55 : :
56 : : #include <vector>
57 : : #include <map>
58 : :
59 : : #include <boost/bind.hpp>
60 : :
61 : : // -----------------------------------------------------------------------------
62 : :
63 : : using namespace ::com::sun::star::uno;
64 : : using namespace ::com::sun::star::style;
65 : : using namespace ::com::sun::star::lang;
66 : : using namespace ::com::sun::star::beans;
67 : : using namespace ::com::sun::star::util;
68 : : using namespace ::com::sun::star::container;
69 : :
70 : : using ::rtl::OUString;
71 : : using ::osl::MutexGuard;
72 : : using ::osl::ClearableMutexGuard;
73 : : using ::cppu::OInterfaceContainerHelper;
74 : :
75 : : namespace sdr { namespace table {
76 : :
77 : : typedef std::map< OUString, sal_Int32 > CellStyleNameMap;
78 : :
79 : : typedef ::cppu::WeakComponentImplHelper6< XStyle, XNameReplace, XServiceInfo, XIndexAccess, XModifyBroadcaster, XModifyListener > TableDesignStyleBase;
80 : :
81 [ + - ][ + + ]: 20364 : class TableDesignStyle : private ::cppu::BaseMutex, public TableDesignStyleBase
[ + - ][ - + ]
82 : : {
83 : : public:
84 : : TableDesignStyle();
85 : :
86 : : // XServiceInfo
87 : : virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
88 : : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
89 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
90 : :
91 : : // XStyle
92 : : virtual ::sal_Bool SAL_CALL isUserDefined() throw (RuntimeException);
93 : : virtual ::sal_Bool SAL_CALL isInUse() throw (RuntimeException);
94 : : virtual OUString SAL_CALL getParentStyle() throw (RuntimeException);
95 : : virtual void SAL_CALL setParentStyle( const OUString& aParentStyle ) throw (NoSuchElementException, RuntimeException);
96 : :
97 : : // XNamed
98 : : virtual OUString SAL_CALL getName() throw (RuntimeException);
99 : : virtual void SAL_CALL setName( const OUString& aName ) throw (RuntimeException);
100 : :
101 : : // XNameAccess
102 : : virtual Any SAL_CALL getByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException);
103 : : virtual Sequence< OUString > SAL_CALL getElementNames() throw(RuntimeException);
104 : : virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(RuntimeException);
105 : :
106 : : // XElementAccess
107 : : virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(RuntimeException);
108 : : virtual sal_Bool SAL_CALL hasElements() throw(RuntimeException);
109 : :
110 : : // XIndexAccess
111 : : virtual sal_Int32 SAL_CALL getCount() throw(RuntimeException) ;
112 : : virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
113 : :
114 : : // XNameReplace
115 : : virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
116 : :
117 : : // XModifyBroadcaster
118 : : virtual void SAL_CALL addModifyListener( const Reference< XModifyListener >& aListener ) throw (RuntimeException);
119 : : virtual void SAL_CALL removeModifyListener( const Reference< XModifyListener >& aListener ) throw (RuntimeException);
120 : :
121 : : // XModifyListener
122 : : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
123 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
124 : :
125 : : void notifyModifyListener();
126 : :
127 : : // this function is called upon disposing the component
128 : : virtual void SAL_CALL disposing();
129 : :
130 : : static const CellStyleNameMap& getCellStyleNameMap();
131 : :
132 : : OUString msName;
133 : : Reference< XStyle > maCellStyles[style_count];
134 : : };
135 : :
136 : : typedef std::vector< Reference< XStyle > > TableDesignStyleVector;
137 : :
138 [ - + ][ + - ]: 528 : class TableDesignFamily : public ::cppu::WeakImplHelper7< XNameContainer, XNamed, XIndexAccess, XSingleServiceFactory, XServiceInfo, XComponent, XPropertySet >
139 : : {
140 : : public:
141 : : // XServiceInfo
142 : : virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
143 : : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
144 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
145 : :
146 : : // XNamed
147 : : virtual OUString SAL_CALL getName( ) throw (RuntimeException);
148 : : virtual void SAL_CALL setName( const OUString& aName ) throw (RuntimeException);
149 : :
150 : : // XNameAccess
151 : : virtual Any SAL_CALL getByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException);
152 : : virtual Sequence< OUString > SAL_CALL getElementNames() throw(RuntimeException);
153 : : virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(RuntimeException);
154 : :
155 : : // XElementAccess
156 : : virtual Type SAL_CALL getElementType() throw(RuntimeException);
157 : : virtual sal_Bool SAL_CALL hasElements() throw(RuntimeException);
158 : :
159 : : // XIndexAccess
160 : : virtual sal_Int32 SAL_CALL getCount() throw(RuntimeException) ;
161 : : virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
162 : :
163 : : // XNameContainer
164 : : virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
165 : : virtual void SAL_CALL removeByName( const OUString& Name ) throw(NoSuchElementException, WrappedTargetException, RuntimeException);
166 : :
167 : : // XNameReplace
168 : : virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
169 : :
170 : : // XSingleServiceFactory
171 : : virtual Reference< XInterface > SAL_CALL createInstance( ) throw(Exception, RuntimeException);
172 : : virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
173 : :
174 : : // XComponent
175 : : virtual void SAL_CALL dispose( ) throw (RuntimeException);
176 : : virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException);
177 : : virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException);
178 : :
179 : : // XPropertySet
180 : : virtual Reference<XPropertySetInfo> SAL_CALL getPropertySetInfo() throw (RuntimeException);
181 : : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
182 : : virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
183 : : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
184 : : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
185 : : virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener>& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
186 : : virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,const Reference<XVetoableChangeListener>&aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
187 : :
188 : : TableDesignStyleVector maDesigns;
189 : : };
190 : :
191 : : //------------------------------------------------------------------------
192 : : // TableDesignStyle
193 : : //------------------------------------------------------------------------
194 : :
195 : 1730 : TableDesignStyle::TableDesignStyle()
196 [ + + ]: 19030 : : TableDesignStyleBase(m_aMutex)
197 : : {
198 : 1730 : }
199 : :
200 : 12110 : const CellStyleNameMap& TableDesignStyle::getCellStyleNameMap()
201 : : {
202 [ + + ][ + - ]: 12110 : static CellStyleNameMap aMap;
[ + - ][ # # ]
203 [ + + ]: 12110 : if( aMap.empty() )
204 : : {
205 [ + - ]: 22 : CellStyleNameMap aNewMap;
206 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "first-row" ) ) ] = first_row_style;
207 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "last-row" ) ) ] = last_row_style;
208 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "first-column" ) ) ] = first_column_style;
209 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "last-column" ) ) ] = last_column_style;
210 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "body" ) ) ] = body_style;
211 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "even-rows" ) ) ] = even_rows_style;
212 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "odd-rows" ) ) ] = odd_rows_style;
213 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "even-columns" ) ) ] = even_columns_style;
214 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "odd-columns" ) ) ] = odd_columns_style;
215 [ + - ][ + - ]: 22 : aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "background" ) ) ] = background_style;
216 [ + - ]: 22 : aMap.swap( aNewMap );
217 : : }
218 : :
219 : 12110 : return aMap;
220 : : }
221 : :
222 : : // ----------------------------------------------------------
223 : : // XServiceInfo
224 : : // ----------------------------------------------------------
225 : :
226 : 0 : OUString SAL_CALL TableDesignStyle::getImplementationName() throw(RuntimeException)
227 : : {
228 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM("TableDesignStyle") );
229 : : }
230 : :
231 : : // ----------------------------------------------------------
232 : :
233 : 0 : sal_Bool SAL_CALL TableDesignStyle::supportsService( const OUString& ServiceName ) throw(RuntimeException)
234 : : {
235 : 0 : return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
236 : : }
237 : :
238 : : // ----------------------------------------------------------
239 : :
240 : 0 : Sequence< OUString > SAL_CALL TableDesignStyle::getSupportedServiceNames() throw(RuntimeException)
241 : : {
242 [ # # ]: 0 : OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.Style") );
243 [ # # ]: 0 : Sequence< OUString > aSeq( &aServiceName, 1 );
244 : 0 : return aSeq;
245 : : }
246 : :
247 : : // ----------------------------------------------------------
248 : : // XStyle
249 : : // ----------------------------------------------------------
250 : :
251 : 0 : sal_Bool SAL_CALL TableDesignStyle::isUserDefined() throw (RuntimeException)
252 : : {
253 : 0 : return sal_False;
254 : : }
255 : :
256 : : // ----------------------------------------------------------
257 : :
258 : 1980 : sal_Bool SAL_CALL TableDesignStyle::isInUse() throw (RuntimeException)
259 : : {
260 [ + - ]: 1980 : ClearableMutexGuard aGuard( rBHelper.rMutex );
261 [ + - ][ + - ]: 1980 : OInterfaceContainerHelper * pContainer = rBHelper.getContainer( XModifyListener::static_type() );
262 [ - + ]: 1980 : if( pContainer )
263 : : {
264 [ # # ]: 0 : Sequence< Reference< XInterface > > aListener( pContainer->getElements() );
265 [ # # ]: 0 : aGuard.clear();
266 : :
267 : 0 : sal_Int32 nIndex = aListener.getLength();
268 [ # # ]: 0 : while( --nIndex >= 0 )
269 : : {
270 [ # # ][ # # ]: 0 : TableDesignUser* pUser = dynamic_cast< TableDesignUser* >( aListener[nIndex].get() );
[ # # ]
271 [ # # ][ # # ]: 0 : if( pUser && pUser->isInUse() )
[ # # ][ # # ]
272 : 0 : return sal_True;
273 [ # # ][ # # ]: 0 : }
274 : : }
275 [ + - ]: 1980 : return sal_False;
276 : : }
277 : :
278 : : // ----------------------------------------------------------
279 : :
280 : 0 : OUString SAL_CALL TableDesignStyle::getParentStyle() throw (RuntimeException)
281 : : {
282 : 0 : return OUString();
283 : : }
284 : :
285 : : // ----------------------------------------------------------
286 : :
287 : 0 : void SAL_CALL TableDesignStyle::setParentStyle( const OUString& ) throw (NoSuchElementException, RuntimeException)
288 : : {
289 : 0 : }
290 : :
291 : : // ----------------------------------------------------------
292 : : // XNamed
293 : : // ----------------------------------------------------------
294 : :
295 : 17282 : OUString SAL_CALL TableDesignStyle::getName() throw (RuntimeException)
296 : : {
297 : 17282 : return msName;
298 : : }
299 : :
300 : : // ----------------------------------------------------------
301 : :
302 : 1730 : void SAL_CALL TableDesignStyle::setName( const OUString& rName ) throw (RuntimeException)
303 : : {
304 : 1730 : msName = rName;
305 : 1730 : }
306 : :
307 : : // ----------------------------------------------------------
308 : : // XNameAccess
309 : : // ----------------------------------------------------------
310 : :
311 : 0 : Any SAL_CALL TableDesignStyle::getByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
312 : : {
313 [ # # ]: 0 : SolarMutexGuard aGuard;
314 : :
315 [ # # ]: 0 : const CellStyleNameMap& rMap = getCellStyleNameMap();
316 : :
317 [ # # ]: 0 : CellStyleNameMap::const_iterator iter = rMap.find( rName );
318 [ # # ]: 0 : if( iter == rMap.end() )
319 [ # # ]: 0 : throw NoSuchElementException();
320 : :
321 [ # # ][ # # ]: 0 : return Any( maCellStyles[(*iter).second] );
322 : : }
323 : :
324 : : // ----------------------------------------------------------
325 : :
326 : 0 : Sequence< OUString > SAL_CALL TableDesignStyle::getElementNames() throw(RuntimeException)
327 : : {
328 [ # # ]: 0 : SolarMutexGuard aGuard;
329 : :
330 [ # # ]: 0 : const CellStyleNameMap& rMap = getCellStyleNameMap();
331 [ # # ]: 0 : Sequence< OUString > aRet( rMap.size() );
332 [ # # ]: 0 : OUString* pName = aRet.getArray();
333 : :
334 : 0 : CellStyleNameMap::const_iterator iter = rMap.begin();
335 [ # # ]: 0 : while( iter != rMap.end() )
336 : 0 : *pName++ = (*iter++).first;
337 : :
338 [ # # ]: 0 : return aRet;
339 : : }
340 : :
341 : : // ----------------------------------------------------------
342 : :
343 : 0 : sal_Bool SAL_CALL TableDesignStyle::hasByName( const OUString& rName ) throw(RuntimeException)
344 : : {
345 [ # # ]: 0 : SolarMutexGuard aGuard;
346 : :
347 [ # # ]: 0 : const CellStyleNameMap& rMap = getCellStyleNameMap();
348 : :
349 [ # # ]: 0 : CellStyleNameMap::const_iterator iter = rMap.find( rName );
350 [ # # ][ # # ]: 0 : return ( iter != rMap.end() ) ? sal_True : sal_False;
351 : : }
352 : :
353 : : // ----------------------------------------------------------
354 : : // XElementAccess
355 : : // ----------------------------------------------------------
356 : :
357 : 0 : Type SAL_CALL TableDesignStyle::getElementType() throw(RuntimeException)
358 : : {
359 : 0 : return XStyle::static_type();
360 : : }
361 : :
362 : : // ----------------------------------------------------------
363 : :
364 : 0 : sal_Bool SAL_CALL TableDesignStyle::hasElements() throw(RuntimeException)
365 : : {
366 : 0 : return sal_True;
367 : : }
368 : :
369 : : // ----------------------------------------------------------
370 : : // XIndexAccess
371 : : // ----------------------------------------------------------
372 : :
373 : 0 : sal_Int32 SAL_CALL TableDesignStyle::getCount() throw(RuntimeException)
374 : : {
375 : 0 : return style_count;
376 : : }
377 : :
378 : : // ----------------------------------------------------------
379 : :
380 : 2032 : Any SAL_CALL TableDesignStyle::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
381 : : {
382 [ + - ]: 2032 : SolarMutexGuard aGuard;
383 : :
384 [ + - ][ - + ]: 2032 : if( (Index < 0) || (Index >= style_count) )
385 [ # # ]: 0 : throw IndexOutOfBoundsException();
386 : :
387 [ + - ][ + - ]: 2032 : return Any( maCellStyles[Index] );
388 : : }
389 : :
390 : : // ----------------------------------------------------------
391 : : // XNameReplace
392 : : // ----------------------------------------------------------
393 : :
394 : 12110 : void SAL_CALL TableDesignStyle::replaceByName( const OUString& rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
395 : : {
396 [ + - ]: 12110 : SolarMutexGuard aGuard;
397 : :
398 [ + - ]: 12110 : const CellStyleNameMap& rMap = getCellStyleNameMap();
399 [ + - ]: 12110 : CellStyleNameMap::const_iterator iter = rMap.find( rName );
400 [ - + ]: 12110 : if( iter == rMap.end() )
401 [ # # ]: 0 : throw NoSuchElementException();
402 : :
403 : :
404 : 12110 : Reference< XStyle > xNewStyle;
405 [ - + ][ + - ]: 12110 : if( !(aElement >>= xNewStyle) )
406 [ # # ]: 0 : throw IllegalArgumentException();
407 : :
408 : 12110 : const sal_Int32 nIndex = (*iter).second;
409 : :
410 : 12110 : Reference< XStyle > xOldStyle( maCellStyles[nIndex] );
411 : :
412 [ + - ][ + - ]: 12110 : if( xNewStyle != xOldStyle )
413 : : {
414 [ + - ]: 12110 : Reference< XModifyListener > xListener( this );
415 : :
416 : : // end listening to old style, if possible
417 [ + - ]: 12110 : Reference< XModifyBroadcaster > xOldBroadcaster( xOldStyle, UNO_QUERY );
418 [ - + ]: 12110 : if( xOldBroadcaster.is() )
419 [ # # ][ # # ]: 0 : xOldBroadcaster->removeModifyListener( xListener );
420 : :
421 : : // start listening to new style, if possible
422 [ + - ]: 12110 : Reference< XModifyBroadcaster > xNewBroadcaster( xNewStyle, UNO_QUERY );
423 [ + - ]: 12110 : if( xNewBroadcaster.is() )
424 [ + - ][ + - ]: 12110 : xNewBroadcaster->addModifyListener( xListener );
425 : :
426 [ + - ]: 12110 : maCellStyles[nIndex] = xNewStyle;
427 [ + - ]: 12110 : }
428 : 12110 : }
429 : :
430 : : // ----------------------------------------------------------
431 : : // XComponent
432 : : // ----------------------------------------------------------
433 : :
434 : 1697 : void SAL_CALL TableDesignStyle::disposing()
435 : : {
436 [ + + ]: 18667 : for( sal_Int32 nIndex = 0; nIndex < style_count; nIndex++ )
437 : 16970 : maCellStyles[nIndex].clear();
438 : 1697 : }
439 : :
440 : : //------------------------------------------------------------------------
441 : : // XModifyBroadcaster
442 : : //------------------------------------------------------------------------
443 : :
444 : 6 : void SAL_CALL TableDesignStyle::addModifyListener( const Reference< XModifyListener >& xListener ) throw (RuntimeException)
445 : : {
446 [ + - ]: 6 : ClearableMutexGuard aGuard( rBHelper.rMutex );
447 [ + - ][ - + ]: 6 : if (rBHelper.bDisposed || rBHelper.bInDispose)
448 : : {
449 [ # # ]: 0 : aGuard.clear();
450 [ # # ][ # # ]: 0 : EventObject aEvt( static_cast< OWeakObject * >( this ) );
451 [ # # ][ # # ]: 0 : xListener->disposing( aEvt );
[ # # ]
452 : : }
453 : : else
454 : : {
455 [ + - ][ + - ]: 6 : rBHelper.addListener( XModifyListener::static_type(), xListener );
456 [ + - ]: 6 : }
457 : 6 : }
458 : :
459 : : //------------------------------------------------------------------------
460 : :
461 : 0 : void SAL_CALL TableDesignStyle::removeModifyListener( const Reference< XModifyListener >& xListener ) throw (RuntimeException)
462 : : {
463 : 0 : rBHelper.removeListener( XModifyListener::static_type(), xListener );
464 : 0 : }
465 : :
466 : : //------------------------------------------------------------------------
467 : :
468 : 12579 : void TableDesignStyle::notifyModifyListener()
469 : : {
470 [ + - ]: 12579 : MutexGuard aGuard( rBHelper.rMutex );
471 : :
472 [ + - ][ + - ]: 12579 : OInterfaceContainerHelper * pContainer = rBHelper.getContainer( XModifyListener::static_type() );
473 [ - + ]: 12579 : if( pContainer )
474 : : {
475 [ # # ][ # # ]: 0 : EventObject aEvt( static_cast< OWeakObject * >( this ) );
476 [ # # ][ # # ]: 0 : pContainer->forEach<XModifyListener>( boost::bind( &XModifyListener::modified, _1, boost::cref( aEvt ) ) );
[ # # ][ # # ]
477 [ + - ]: 12579 : }
478 : 12579 : }
479 : :
480 : : //------------------------------------------------------------------------
481 : : // XModifyListener
482 : : //------------------------------------------------------------------------
483 : :
484 : : // if we get a modify hint from a style, notify all registered XModifyListener
485 : 12579 : void SAL_CALL TableDesignStyle::modified( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
486 : : {
487 : 12579 : notifyModifyListener();
488 : 12579 : }
489 : :
490 : : //------------------------------------------------------------------------
491 : :
492 : 11879 : void SAL_CALL TableDesignStyle::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
493 : : {
494 : 11879 : }
495 : :
496 : : //------------------------------------------------------------------------
497 : : // TableStyle
498 : : //------------------------------------------------------------------------
499 : :
500 : : // ----------------------------------------------------------
501 : : // XServiceInfo
502 : : // ----------------------------------------------------------
503 : :
504 : 0 : OUString SAL_CALL TableDesignFamily::getImplementationName() throw(RuntimeException)
505 : : {
506 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM("TableDesignFamily") );
507 : : }
508 : :
509 : : // ----------------------------------------------------------
510 : :
511 : 0 : sal_Bool SAL_CALL TableDesignFamily::supportsService( const OUString& ServiceName ) throw(RuntimeException)
512 : : {
513 : 0 : return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
514 : : }
515 : :
516 : : // ----------------------------------------------------------
517 : :
518 : 0 : Sequence< OUString > SAL_CALL TableDesignFamily::getSupportedServiceNames() throw(RuntimeException)
519 : : {
520 [ # # ]: 0 : OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.StyleFamily") );
521 [ # # ]: 0 : Sequence< OUString > aSeq( &aServiceName, 1 );
522 : 0 : return aSeq;
523 : : }
524 : :
525 : : // ----------------------------------------------------------
526 : : // XNamed
527 : : // ----------------------------------------------------------
528 : :
529 : 178 : OUString SAL_CALL TableDesignFamily::getName() throw (RuntimeException)
530 : : {
531 : 178 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) );
532 : : }
533 : :
534 : : // ----------------------------------------------------------
535 : :
536 : 0 : void SAL_CALL TableDesignFamily::setName( const OUString& ) throw (RuntimeException)
537 : : {
538 : 0 : }
539 : :
540 : : // ----------------------------------------------------------
541 : : // XNameAccess
542 : : // ----------------------------------------------------------
543 : :
544 : 6 : Any SAL_CALL TableDesignFamily::getByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
545 : : {
546 [ + - ]: 6 : SolarMutexGuard aGuard;
547 : :
548 [ # # ][ + - ]: 6 : for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
[ + - ]
549 : : {
550 [ + - ][ + - ]: 6 : if( (*iter)->getName() == rName )
[ + - ]
551 [ + - ]: 12 : return Any( (*iter) );
552 : : }
553 : :
554 [ # # ][ + - ]: 6 : throw NoSuchElementException();
555 : : }
556 : :
557 : : // ----------------------------------------------------------
558 : :
559 : 0 : Sequence< OUString > SAL_CALL TableDesignFamily::getElementNames() throw(RuntimeException)
560 : : {
561 [ # # ]: 0 : SolarMutexGuard aGuard;
562 : :
563 [ # # ]: 0 : Sequence< OUString > aRet( maDesigns.size() );
564 [ # # ]: 0 : OUString* pNames = aRet.getArray();
565 : :
566 [ # # ][ # # ]: 0 : for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
[ # # ]
567 [ # # ][ # # ]: 0 : *pNames++ = (*iter)->getName();
568 : :
569 [ # # ]: 0 : return aRet;
570 : : }
571 : :
572 : : // ----------------------------------------------------------
573 : :
574 : 1730 : sal_Bool SAL_CALL TableDesignFamily::hasByName( const OUString& aName ) throw(RuntimeException)
575 : : {
576 [ + - ]: 1730 : SolarMutexGuard aGuard;
577 : :
578 [ + - ][ + - ]: 10365 : for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
[ + + ]
579 [ + - ][ + - ]: 8638 : if( (*iter)->getName() == aName )
[ + + ]
580 : 3 : return sal_True;
581 : :
582 [ + - ]: 1730 : return sal_False;
583 : : }
584 : :
585 : : // ----------------------------------------------------------
586 : : // XElementAccess
587 : : // ----------------------------------------------------------
588 : :
589 : 0 : Type SAL_CALL TableDesignFamily::getElementType() throw(RuntimeException)
590 : : {
591 : 0 : return XStyle::static_type();
592 : : }
593 : :
594 : : // ----------------------------------------------------------
595 : :
596 : 0 : sal_Bool SAL_CALL TableDesignFamily::hasElements() throw(RuntimeException)
597 : : {
598 [ # # ]: 0 : SolarMutexGuard aGuard;
599 : :
600 [ # # ][ # # ]: 0 : return maDesigns.empty() ? sal_False : sal_True;
601 : : }
602 : :
603 : : // ----------------------------------------------------------
604 : : // XIndexAccess
605 : : // ----------------------------------------------------------
606 : :
607 : 348 : sal_Int32 SAL_CALL TableDesignFamily::getCount() throw(RuntimeException)
608 : : {
609 [ + - ]: 348 : SolarMutexGuard aGuard;
610 : :
611 [ + - ]: 348 : return sal::static_int_cast< sal_Int32 >( maDesigns.size() );
612 : : }
613 : :
614 : : // ----------------------------------------------------------
615 : :
616 : 319 : Any SAL_CALL TableDesignFamily::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
617 : : {
618 [ + - ]: 319 : SolarMutexGuard aGuard;
619 : :
620 [ + - ][ + - ]: 319 : if( (Index >= 0) && (Index < sal::static_int_cast< sal_Int32 >( maDesigns.size() ) ) )
[ + - ]
621 [ + - ]: 638 : return Any( maDesigns[Index] );
622 : :
623 [ # # ][ + - ]: 319 : throw IndexOutOfBoundsException();
624 : : }
625 : :
626 : : // ----------------------------------------------------------
627 : : // XNameContainer
628 : : // ----------------------------------------------------------
629 : :
630 : 1727 : void SAL_CALL TableDesignFamily::insertByName( const OUString& rName, const Any& rElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
631 : : {
632 [ + - ]: 1727 : SolarMutexGuard aGuard;
633 : :
634 [ + - ]: 1727 : Reference< XStyle > xStyle( rElement, UNO_QUERY );
635 [ - + ]: 1727 : if( !xStyle.is() )
636 [ # # ]: 0 : throw IllegalArgumentException();
637 : :
638 [ + - ][ + - ]: 1727 : xStyle->setName( rName );
639 [ + - ][ + - ]: 10362 : for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
[ + + ]
640 [ + - ][ + - ]: 8635 : if( (*iter)->getName() == rName )
[ - + ]
641 [ # # ]: 0 : throw ElementExistException();
642 : :
643 [ + - ][ + - ]: 1727 : maDesigns.push_back( xStyle );
644 : 1727 : }
645 : :
646 : : // ----------------------------------------------------------
647 : :
648 : 0 : void SAL_CALL TableDesignFamily::removeByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
649 : : {
650 [ # # ]: 0 : SolarMutexGuard aGuard;
651 : :
652 [ # # ][ # # ]: 0 : for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
[ # # ]
653 : : {
654 [ # # ][ # # ]: 0 : if( (*iter)->getName() == rName )
[ # # ]
655 : : {
656 [ # # ]: 0 : maDesigns.erase( iter );
657 : 0 : return;
658 : : }
659 : : }
660 : :
661 : :
662 [ # # ][ # # ]: 0 : throw NoSuchElementException();
663 : : }
664 : :
665 : : // ----------------------------------------------------------
666 : : // XNameReplace
667 : : // ----------------------------------------------------------
668 : :
669 : 3 : void SAL_CALL TableDesignFamily::replaceByName( const OUString& rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
670 : : {
671 [ + - ]: 3 : SolarMutexGuard aGuard;
672 : :
673 [ + - ]: 3 : Reference< XStyle > xStyle( aElement, UNO_QUERY );
674 [ - + ]: 3 : if( !xStyle.is() )
675 [ # # ]: 0 : throw IllegalArgumentException();
676 : :
677 [ # # ][ + - ]: 3 : for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
[ + - ]
678 : : {
679 [ + - ][ + - ]: 3 : if( (*iter)->getName() == rName )
[ + - ]
680 : : {
681 [ + - ]: 3 : (*iter) = xStyle;
682 [ + - ][ + - ]: 3 : xStyle->setName( rName );
683 : 3 : return;
684 : : }
685 : : }
686 : :
687 [ # # ][ + - ]: 3 : throw NoSuchElementException();
688 : : }
689 : :
690 : : // ----------------------------------------------------------
691 : : // XSingleServiceFactory
692 : : // ----------------------------------------------------------
693 : :
694 : 1730 : Reference< XInterface > SAL_CALL TableDesignFamily::createInstance() throw(Exception, RuntimeException)
695 : : {
696 [ + - ]: 1730 : SolarMutexGuard aGuard;
697 : :
698 [ + - ][ + - ]: 1730 : return Reference< XInterface >( static_cast< XStyle* >( new TableDesignStyle ) );
[ + - ][ + - ]
699 : : }
700 : :
701 : : // ----------------------------------------------------------
702 : :
703 : 0 : Reference< XInterface > SAL_CALL TableDesignFamily::createInstanceWithArguments( const Sequence< Any >& ) throw(Exception, RuntimeException)
704 : : {
705 : 0 : return createInstance();
706 : : }
707 : :
708 : : // ----------------------------------------------------------
709 : : // XComponent
710 : : // ----------------------------------------------------------
711 : :
712 : 175 : void SAL_CALL TableDesignFamily::dispose( ) throw (RuntimeException)
713 : : {
714 [ + - ]: 175 : TableDesignStyleVector aDesigns;
715 : 175 : aDesigns.swap( maDesigns );
716 : :
717 [ + - ][ + + ]: 1869 : for( TableDesignStyleVector::iterator iter( aDesigns.begin() ); iter != aDesigns.end(); ++iter )
718 : : {
719 [ + - ]: 1694 : Reference< XComponent > xComp( (*iter), UNO_QUERY );
720 [ + - ]: 1694 : if( xComp.is() )
721 [ + - ][ + - ]: 1694 : xComp->dispose();
722 : 1869 : }
723 : 175 : }
724 : :
725 : : // ----------------------------------------------------------
726 : :
727 : 0 : void SAL_CALL TableDesignFamily::addEventListener( const Reference< XEventListener >& ) throw (RuntimeException)
728 : : {
729 : 0 : }
730 : :
731 : : // ----------------------------------------------------------
732 : :
733 : 0 : void SAL_CALL TableDesignFamily::removeEventListener( const Reference< XEventListener >& ) throw (RuntimeException)
734 : : {
735 : 0 : }
736 : :
737 : : // ----------------------------------------------------------
738 : : // XPropertySet
739 : : // ----------------------------------------------------------
740 : :
741 : 0 : Reference<XPropertySetInfo> TableDesignFamily::getPropertySetInfo() throw (RuntimeException)
742 : : {
743 : : OSL_FAIL( "###unexpected!" );
744 : 0 : return Reference<XPropertySetInfo>();
745 : : }
746 : :
747 : : // ----------------------------------------------------------
748 : :
749 : 0 : void TableDesignFamily::setPropertyValue( const OUString& , const Any& ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
750 : : {
751 : : OSL_FAIL( "###unexpected!" );
752 : 0 : }
753 : :
754 : : // ----------------------------------------------------------
755 : :
756 : 0 : Any TableDesignFamily::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
757 : : {
758 [ # # ]: 0 : if ( PropertyName == "DisplayName" )
759 : : {
760 [ # # ][ # # ]: 0 : OUString sDisplayName( SVX_RESSTR( RID_SVXSTR_STYLEFAMILY_TABLEDESIGN ) );
761 [ # # ]: 0 : return Any( sDisplayName );
762 : : }
763 : : else
764 : : {
765 [ # # ][ # # ]: 0 : throw UnknownPropertyException( OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property: ") ) + PropertyName, static_cast<OWeakObject *>(this) );
[ # # ]
766 : : }
767 : : }
768 : :
769 : : // ----------------------------------------------------------
770 : :
771 : 0 : void TableDesignFamily::addPropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
772 : : {
773 : : OSL_FAIL( "###unexpected!" );
774 : 0 : }
775 : :
776 : : // ----------------------------------------------------------
777 : :
778 : 0 : void TableDesignFamily::removePropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
779 : : {
780 : : OSL_FAIL( "###unexpected!" );
781 : 0 : }
782 : :
783 : : // ----------------------------------------------------------
784 : :
785 : 0 : void TableDesignFamily::addVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
786 : : {
787 : : OSL_FAIL( "###unexpected!" );
788 : 0 : }
789 : :
790 : : // ----------------------------------------------------------
791 : :
792 : 0 : void TableDesignFamily::removeVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
793 : : {
794 : : OSL_FAIL( "###unexpected!" );
795 : 0 : }
796 : :
797 : : // --------------------------------------------------------------------
798 : :
799 : :
800 : 178 : SVX_DLLPUBLIC Reference< XNameAccess > CreateTableDesignFamily()
801 : : {
802 [ + - ][ + - ]: 178 : return new TableDesignFamily();
803 : : }
804 : :
805 [ + - ][ + - ]: 417 : } }
806 : :
807 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|