update dev300-m58
[ooovba.git] / svx / source / table / tabledesign.cxx
blob214ca0bad82ee99ff29313f7f11b7781014d9f8b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabledesign.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <com/sun/star/style/XStyle.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <com/sun/star/container/XIndexAccess.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/util/XModifyBroadcaster.hpp>
42 #include <com/sun/star/util/XModifyListener.hpp>
44 #include <osl/mutex.hxx>
45 #include <vos/mutex.hxx>
46 #include <vcl/svapp.hxx>
48 #include <cppuhelper/basemutex.hxx>
49 #include <cppuhelper/compbase6.hxx>
50 #include <cppuhelper/implbase7.hxx>
51 #include <cppuhelper/interfacecontainer.h>
53 #include "svx/unoprov.hxx"
54 #include "svx/sdr/table/tabledesign.hxx"
55 #include "svx/dialmgr.hxx"
56 #include "svx/dialogs.hrc"
58 #include "celltypes.hxx"
60 #include <vector>
61 #include <map>
63 #include <boost/bind.hpp>
65 // -----------------------------------------------------------------------------
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::style;
69 using namespace ::com::sun::star::lang;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::util;
72 using namespace ::com::sun::star::container;
74 using ::rtl::OUString;
75 using ::vos::OGuard;
76 using ::osl::MutexGuard;
77 using ::osl::ClearableMutexGuard;
78 using ::cppu::OInterfaceContainerHelper;
80 namespace sdr { namespace table {
82 typedef std::map< OUString, sal_Int32 > CellStyleNameMap;
84 typedef ::cppu::WeakComponentImplHelper6< XStyle, XNameReplace, XServiceInfo, XIndexAccess, XModifyBroadcaster, XModifyListener > TableDesignStyleBase;
86 class TableDesignStyle : private ::cppu::BaseMutex, public TableDesignStyleBase
88 public:
89 TableDesignStyle();
91 // XServiceInfo
92 virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
93 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
94 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
96 // XStyle
97 virtual ::sal_Bool SAL_CALL isUserDefined() throw (RuntimeException);
98 virtual ::sal_Bool SAL_CALL isInUse() throw (RuntimeException);
99 virtual OUString SAL_CALL getParentStyle() throw (RuntimeException);
100 virtual void SAL_CALL setParentStyle( const OUString& aParentStyle ) throw (NoSuchElementException, RuntimeException);
102 // XNamed
103 virtual OUString SAL_CALL getName() throw (RuntimeException);
104 virtual void SAL_CALL setName( const OUString& aName ) throw (RuntimeException);
106 // XNameAccess
107 virtual Any SAL_CALL getByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException);
108 virtual Sequence< OUString > SAL_CALL getElementNames() throw(RuntimeException);
109 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(RuntimeException);
111 // XElementAccess
112 virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(RuntimeException);
113 virtual sal_Bool SAL_CALL hasElements() throw(RuntimeException);
115 // XIndexAccess
116 virtual sal_Int32 SAL_CALL getCount() throw(RuntimeException) ;
117 virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
119 // XNameReplace
120 virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
122 // XModifyBroadcaster
123 virtual void SAL_CALL addModifyListener( const Reference< XModifyListener >& aListener ) throw (RuntimeException);
124 virtual void SAL_CALL removeModifyListener( const Reference< XModifyListener >& aListener ) throw (RuntimeException);
126 // XModifyListener
127 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
128 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
130 void notifyModifyListener();
132 // this function is called upon disposing the component
133 virtual void SAL_CALL disposing();
135 static const CellStyleNameMap& getCellStyleNameMap();
137 OUString msName;
138 Reference< XStyle > maCellStyles[style_count];
141 typedef std::vector< Reference< XStyle > > TableDesignStyleVector;
143 class TableDesignFamily : public ::cppu::WeakImplHelper7< XNameContainer, XNamed, XIndexAccess, XSingleServiceFactory, XServiceInfo, XComponent, XPropertySet >
145 public:
146 // XServiceInfo
147 virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
148 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
149 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
151 // XNamed
152 virtual OUString SAL_CALL getName( ) throw (RuntimeException);
153 virtual void SAL_CALL setName( const OUString& aName ) throw (RuntimeException);
155 // XNameAccess
156 virtual Any SAL_CALL getByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException);
157 virtual Sequence< OUString > SAL_CALL getElementNames() throw(RuntimeException);
158 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(RuntimeException);
160 // XElementAccess
161 virtual Type SAL_CALL getElementType() throw(RuntimeException);
162 virtual sal_Bool SAL_CALL hasElements() throw(RuntimeException);
164 // XIndexAccess
165 virtual sal_Int32 SAL_CALL getCount() throw(RuntimeException) ;
166 virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
168 // XNameContainer
169 virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
170 virtual void SAL_CALL removeByName( const OUString& Name ) throw(NoSuchElementException, WrappedTargetException, RuntimeException);
172 // XNameReplace
173 virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
175 // XSingleServiceFactory
176 virtual Reference< XInterface > SAL_CALL createInstance( ) throw(Exception, RuntimeException);
177 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
179 // XComponent
180 virtual void SAL_CALL dispose( ) throw (RuntimeException);
181 virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException);
182 virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException);
184 // XPropertySet
185 virtual Reference<XPropertySetInfo> SAL_CALL getPropertySetInfo() throw (RuntimeException);
186 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
187 virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
188 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
189 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference<XPropertyChangeListener>& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
190 virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener>& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
191 virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,const Reference<XVetoableChangeListener>&aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
193 TableDesignStyleVector maDesigns;
196 //------------------------------------------------------------------------
197 // TableDesignStyle
198 //------------------------------------------------------------------------
200 TableDesignStyle::TableDesignStyle()
201 : TableDesignStyleBase(m_aMutex)
205 const CellStyleNameMap& TableDesignStyle::getCellStyleNameMap()
207 static CellStyleNameMap aMap;
208 if( aMap.empty() )
210 CellStyleNameMap aNewMap;
211 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "first-row" ) ) ] = first_row_style;
212 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "last-row" ) ) ] = last_row_style;
213 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "first-column" ) ) ] = first_column_style;
214 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "last-column" ) ) ] = last_column_style;
215 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "body" ) ) ] = body_style;
216 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "even-rows" ) ) ] = even_rows_style;
217 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "odd-rows" ) ) ] = odd_rows_style;
218 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "even-columns" ) ) ] = even_columns_style;
219 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "odd-columns" ) ) ] = odd_columns_style;
220 aNewMap[ OUString( RTL_CONSTASCII_USTRINGPARAM( "background" ) ) ] = background_style;
221 aMap.swap( aNewMap );
224 return aMap;
227 // ----------------------------------------------------------
228 // XServiceInfo
229 // ----------------------------------------------------------
231 OUString SAL_CALL TableDesignStyle::getImplementationName() throw(RuntimeException)
233 return OUString( RTL_CONSTASCII_USTRINGPARAM("TableDesignStyle") );
236 // ----------------------------------------------------------
238 sal_Bool SAL_CALL TableDesignStyle::supportsService( const OUString& ServiceName ) throw(RuntimeException)
240 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
243 // ----------------------------------------------------------
245 Sequence< OUString > SAL_CALL TableDesignStyle::getSupportedServiceNames() throw(RuntimeException)
247 OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.Style") );
248 Sequence< OUString > aSeq( &aServiceName, 1 );
249 return aSeq;
252 // ----------------------------------------------------------
253 // XStyle
254 // ----------------------------------------------------------
256 sal_Bool SAL_CALL TableDesignStyle::isUserDefined() throw (RuntimeException)
258 return sal_False;
261 // ----------------------------------------------------------
263 sal_Bool SAL_CALL TableDesignStyle::isInUse() throw (RuntimeException)
265 ClearableMutexGuard aGuard( rBHelper.rMutex );
266 OInterfaceContainerHelper * pContainer = rBHelper.getContainer( XModifyListener::static_type() );
267 if( pContainer )
269 Sequence< Reference< XInterface > > aListener( pContainer->getElements() );
270 aGuard.clear();
272 sal_Int32 nIndex = aListener.getLength();
273 while( --nIndex >= 0 )
275 TableDesignUser* pUser = dynamic_cast< TableDesignUser* >( aListener[nIndex].get() );
276 if( pUser && pUser->isInUse() )
277 return sal_True;
280 return sal_False;
283 // ----------------------------------------------------------
285 OUString SAL_CALL TableDesignStyle::getParentStyle() throw (RuntimeException)
287 return OUString();
290 // ----------------------------------------------------------
292 void SAL_CALL TableDesignStyle::setParentStyle( const OUString& ) throw (NoSuchElementException, RuntimeException)
296 // ----------------------------------------------------------
297 // XNamed
298 // ----------------------------------------------------------
300 OUString SAL_CALL TableDesignStyle::getName() throw (RuntimeException)
302 return msName;
305 // ----------------------------------------------------------
307 void SAL_CALL TableDesignStyle::setName( const OUString& rName ) throw (RuntimeException)
309 msName = rName;
312 // ----------------------------------------------------------
313 // XNameAccess
314 // ----------------------------------------------------------
316 Any SAL_CALL TableDesignStyle::getByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
318 OGuard aGuard( Application::GetSolarMutex() );
320 const CellStyleNameMap& rMap = getCellStyleNameMap();
322 CellStyleNameMap::const_iterator iter = rMap.find( rName );
323 if( iter == rMap.end() )
324 throw NoSuchElementException();
326 return Any( maCellStyles[(*iter).second] );
329 // ----------------------------------------------------------
331 Sequence< OUString > SAL_CALL TableDesignStyle::getElementNames() throw(RuntimeException)
333 OGuard aGuard( Application::GetSolarMutex() );
335 const CellStyleNameMap& rMap = getCellStyleNameMap();
336 Sequence< OUString > aRet( rMap.size() );
337 OUString* pName = aRet.getArray();
339 CellStyleNameMap::const_iterator iter = rMap.begin();
340 while( iter != rMap.end() )
341 *pName++ = (*iter++).first;
343 return aRet;
346 // ----------------------------------------------------------
348 sal_Bool SAL_CALL TableDesignStyle::hasByName( const OUString& rName ) throw(RuntimeException)
350 OGuard aGuard( Application::GetSolarMutex() );
352 const CellStyleNameMap& rMap = getCellStyleNameMap();
354 CellStyleNameMap::const_iterator iter = rMap.find( rName );
355 return ( iter != rMap.end() ) ? sal_True : sal_False;
358 // ----------------------------------------------------------
359 // XElementAccess
360 // ----------------------------------------------------------
362 Type SAL_CALL TableDesignStyle::getElementType() throw(RuntimeException)
364 return XStyle::static_type();
367 // ----------------------------------------------------------
369 sal_Bool SAL_CALL TableDesignStyle::hasElements() throw(RuntimeException)
371 return sal_True;
374 // ----------------------------------------------------------
375 // XIndexAccess
376 // ----------------------------------------------------------
378 sal_Int32 SAL_CALL TableDesignStyle::getCount() throw(RuntimeException)
380 return style_count;
383 // ----------------------------------------------------------
385 Any SAL_CALL TableDesignStyle::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
387 OGuard aGuard( Application::GetSolarMutex() );
389 if( (Index < 0) || (Index >= style_count) )
390 throw IndexOutOfBoundsException();
392 return Any( maCellStyles[Index] );
395 // ----------------------------------------------------------
396 // XNameReplace
397 // ----------------------------------------------------------
399 void SAL_CALL TableDesignStyle::replaceByName( const OUString& rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
401 OGuard aGuard( Application::GetSolarMutex() );
403 const CellStyleNameMap& rMap = getCellStyleNameMap();
404 CellStyleNameMap::const_iterator iter = rMap.find( rName );
405 if( iter == rMap.end() )
406 throw NoSuchElementException();
409 Reference< XStyle > xNewStyle;
410 if( !(aElement >>= xNewStyle) )
411 throw IllegalArgumentException();
413 const sal_Int32 nIndex = (*iter).second;
415 Reference< XStyle > xOldStyle( maCellStyles[nIndex] );
417 if( xNewStyle != xOldStyle )
419 Reference< XModifyListener > xListener( this );
421 // end listening to old style, if possible
422 Reference< XModifyBroadcaster > xOldBroadcaster( xOldStyle, UNO_QUERY );
423 if( xOldBroadcaster.is() )
424 xOldBroadcaster->removeModifyListener( xListener );
426 // start listening to new style, if possible
427 Reference< XModifyBroadcaster > xNewBroadcaster( xNewStyle, UNO_QUERY );
428 if( xNewBroadcaster.is() )
429 xNewBroadcaster->addModifyListener( xListener );
431 maCellStyles[nIndex] = xNewStyle;
435 // ----------------------------------------------------------
436 // XComponent
437 // ----------------------------------------------------------
439 void SAL_CALL TableDesignStyle::disposing()
441 for( sal_Int32 nIndex = 0; nIndex < style_count; nIndex++ )
442 maCellStyles[nIndex].clear();
445 //------------------------------------------------------------------------
446 // XModifyBroadcaster
447 //------------------------------------------------------------------------
449 void SAL_CALL TableDesignStyle::addModifyListener( const Reference< XModifyListener >& xListener ) throw (RuntimeException)
451 ClearableMutexGuard aGuard( rBHelper.rMutex );
452 if (rBHelper.bDisposed || rBHelper.bInDispose)
454 aGuard.clear();
455 EventObject aEvt( static_cast< OWeakObject * >( this ) );
456 xListener->disposing( aEvt );
458 else
460 rBHelper.addListener( XModifyListener::static_type(), xListener );
464 //------------------------------------------------------------------------
466 void SAL_CALL TableDesignStyle::removeModifyListener( const Reference< XModifyListener >& xListener ) throw (RuntimeException)
468 rBHelper.removeListener( XModifyListener::static_type(), xListener );
471 //------------------------------------------------------------------------
473 void TableDesignStyle::notifyModifyListener()
475 MutexGuard aGuard( rBHelper.rMutex );
477 OInterfaceContainerHelper * pContainer = rBHelper.getContainer( XModifyListener::static_type() );
478 if( pContainer )
480 EventObject aEvt( static_cast< OWeakObject * >( this ) );
481 pContainer->forEach<XModifyListener>( boost::bind( &XModifyListener::modified, _1, boost::cref( aEvt ) ) );
485 //------------------------------------------------------------------------
486 // XModifyListener
487 //------------------------------------------------------------------------
489 // if we get a modify hint from a style, notify all registered XModifyListener
490 void SAL_CALL TableDesignStyle::modified( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
492 notifyModifyListener();
495 //------------------------------------------------------------------------
497 void SAL_CALL TableDesignStyle::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
501 //------------------------------------------------------------------------
502 // TableStyle
503 //------------------------------------------------------------------------
505 // ----------------------------------------------------------
506 // XServiceInfo
507 // ----------------------------------------------------------
509 OUString SAL_CALL TableDesignFamily::getImplementationName() throw(RuntimeException)
511 return OUString( RTL_CONSTASCII_USTRINGPARAM("TableDesignFamily") );
514 // ----------------------------------------------------------
516 sal_Bool SAL_CALL TableDesignFamily::supportsService( const OUString& ServiceName ) throw(RuntimeException)
518 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
521 // ----------------------------------------------------------
523 Sequence< OUString > SAL_CALL TableDesignFamily::getSupportedServiceNames() throw(RuntimeException)
525 OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.StyleFamily") );
526 Sequence< OUString > aSeq( &aServiceName, 1 );
527 return aSeq;
530 // ----------------------------------------------------------
531 // XNamed
532 // ----------------------------------------------------------
534 OUString SAL_CALL TableDesignFamily::getName() throw (RuntimeException)
536 return OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) );
539 // ----------------------------------------------------------
541 void SAL_CALL TableDesignFamily::setName( const OUString& ) throw (RuntimeException)
545 // ----------------------------------------------------------
546 // XNameAccess
547 // ----------------------------------------------------------
549 Any SAL_CALL TableDesignFamily::getByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
551 OGuard aGuard( Application::GetSolarMutex() );
553 for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
555 if( (*iter)->getName() == rName )
556 return Any( (*iter) );
559 throw NoSuchElementException();
562 // ----------------------------------------------------------
564 Sequence< OUString > SAL_CALL TableDesignFamily::getElementNames() throw(RuntimeException)
566 OGuard aGuard( Application::GetSolarMutex() );
568 Sequence< OUString > aRet( maDesigns.size() );
569 OUString* pNames = aRet.getArray();
571 for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
572 *pNames++ = (*iter)->getName();
574 return aRet;
577 // ----------------------------------------------------------
579 sal_Bool SAL_CALL TableDesignFamily::hasByName( const OUString& aName ) throw(RuntimeException)
581 OGuard aGuard( Application::GetSolarMutex() );
583 for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
584 if( (*iter)->getName() == aName )
585 return sal_True;
587 return sal_False;
590 // ----------------------------------------------------------
591 // XElementAccess
592 // ----------------------------------------------------------
594 Type SAL_CALL TableDesignFamily::getElementType() throw(RuntimeException)
596 return XStyle::static_type();
599 // ----------------------------------------------------------
601 sal_Bool SAL_CALL TableDesignFamily::hasElements() throw(RuntimeException)
603 OGuard aGuard( Application::GetSolarMutex() );
605 return maDesigns.empty() ? sal_False : sal_True;
608 // ----------------------------------------------------------
609 // XIndexAccess
610 // ----------------------------------------------------------
612 sal_Int32 SAL_CALL TableDesignFamily::getCount() throw(RuntimeException)
614 OGuard aGuard( Application::GetSolarMutex() );
616 return sal::static_int_cast< sal_Int32 >( maDesigns.size() );
619 // ----------------------------------------------------------
621 Any SAL_CALL TableDesignFamily::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
623 OGuard aGuard( Application::GetSolarMutex() );
625 if( (Index >= 0) && (Index < sal::static_int_cast< sal_Int32 >( maDesigns.size() ) ) )
626 return Any( maDesigns[Index] );
628 throw IndexOutOfBoundsException();
631 // ----------------------------------------------------------
632 // XNameContainer
633 // ----------------------------------------------------------
635 void SAL_CALL TableDesignFamily::insertByName( const OUString& rName, const Any& rElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
637 OGuard aGuard( Application::GetSolarMutex() );
639 Reference< XStyle > xStyle( rElement, UNO_QUERY );
640 if( !xStyle.is() )
641 throw IllegalArgumentException();
643 xStyle->setName( rName );
644 for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
645 if( (*iter)->getName() == rName )
646 throw ElementExistException();
648 maDesigns.push_back( xStyle );
651 // ----------------------------------------------------------
653 void SAL_CALL TableDesignFamily::removeByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
655 OGuard aGuard( Application::GetSolarMutex() );
657 for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
659 if( (*iter)->getName() == rName )
661 maDesigns.erase( iter );
662 return;
667 throw NoSuchElementException();
670 // ----------------------------------------------------------
671 // XNameReplace
672 // ----------------------------------------------------------
674 void SAL_CALL TableDesignFamily::replaceByName( const OUString& rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
676 OGuard aGuard( Application::GetSolarMutex() );
678 Reference< XStyle > xStyle( aElement, UNO_QUERY );
679 if( !xStyle.is() )
680 throw IllegalArgumentException();
682 for( TableDesignStyleVector::iterator iter( maDesigns.begin() ); iter != maDesigns.end(); iter++ )
684 if( (*iter)->getName() == rName )
686 (*iter) = xStyle;
687 xStyle->setName( rName );
688 return;
692 throw NoSuchElementException();
695 // ----------------------------------------------------------
696 // XSingleServiceFactory
697 // ----------------------------------------------------------
699 Reference< XInterface > SAL_CALL TableDesignFamily::createInstance() throw(Exception, RuntimeException)
701 OGuard aGuard( Application::GetSolarMutex() );
703 return Reference< XInterface >( static_cast< XStyle* >( new TableDesignStyle ) );
706 // ----------------------------------------------------------
708 Reference< XInterface > SAL_CALL TableDesignFamily::createInstanceWithArguments( const Sequence< Any >& ) throw(Exception, RuntimeException)
710 return createInstance();
713 // ----------------------------------------------------------
714 // XComponent
715 // ----------------------------------------------------------
717 void SAL_CALL TableDesignFamily::dispose( ) throw (RuntimeException)
719 TableDesignStyleVector aDesigns;
720 aDesigns.swap( maDesigns );
722 for( TableDesignStyleVector::iterator iter( aDesigns.begin() ); iter != aDesigns.end(); iter++ )
724 Reference< XComponent > xComp( (*iter), UNO_QUERY );
725 if( xComp.is() )
726 xComp->dispose();
730 // ----------------------------------------------------------
732 void SAL_CALL TableDesignFamily::addEventListener( const Reference< XEventListener >& ) throw (RuntimeException)
736 // ----------------------------------------------------------
738 void SAL_CALL TableDesignFamily::removeEventListener( const Reference< XEventListener >& ) throw (RuntimeException)
742 // ----------------------------------------------------------
743 // XPropertySet
744 // ----------------------------------------------------------
746 Reference<XPropertySetInfo> TableDesignFamily::getPropertySetInfo() throw (RuntimeException)
748 OSL_ENSURE( 0, "###unexpected!" );
749 return Reference<XPropertySetInfo>();
752 // ----------------------------------------------------------
754 void TableDesignFamily::setPropertyValue( const OUString& , const Any& ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
756 OSL_ENSURE( 0, "###unexpected!" );
759 // ----------------------------------------------------------
761 Any TableDesignFamily::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
763 if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DisplayName") ))
765 OUString sDisplayName( SVX_RESSTR( RID_SVXSTR_STYLEFAMILY_TABLEDESIGN ) );
766 return Any( sDisplayName );
768 else
770 throw UnknownPropertyException( OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property: ") ) + PropertyName, static_cast<OWeakObject *>(this) );
774 // ----------------------------------------------------------
776 void TableDesignFamily::addPropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
778 OSL_ENSURE( 0, "###unexpected!" );
781 // ----------------------------------------------------------
783 void TableDesignFamily::removePropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
785 OSL_ENSURE( 0, "###unexpected!" );
788 // ----------------------------------------------------------
790 void TableDesignFamily::addVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
792 OSL_ENSURE( 0, "###unexpected!" );
795 // ----------------------------------------------------------
797 void TableDesignFamily::removeVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
799 OSL_ENSURE( 0, "###unexpected!" );
802 // --------------------------------------------------------------------
805 SVX_DLLPUBLIC Reference< XNameAccess > CreateTableDesignFamily()
807 return new TableDesignFamily();