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