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