21#include <com/sun/star/style/XStyle.hpp>
22#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23#include <com/sun/star/lang/XServiceInfo.hpp>
24#include <com/sun/star/lang/XComponent.hpp>
25#include <com/sun/star/lang/XSingleServiceFactory.hpp>
26#include <com/sun/star/container/XIndexReplace.hpp>
27#include <com/sun/star/container/XNameContainer.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/util/XModifiable.hpp>
30#include <com/sun/star/util/XModifyListener.hpp>
31#include <com/sun/star/form/XReset.hpp>
43#include <svx/strings.hrc>
63typedef ::comphelper::WeakComponentImplHelper< XStyle, XNameReplace, XServiceInfo, XIndexReplace, XModifiable, XModifyListener, XPropertySet >
TableDesignStyleBase;
78 virtual sal_Bool SAL_CALL isUserDefined()
override;
79 virtual sal_Bool SAL_CALL isInUse()
override;
80 virtual OUString SAL_CALL getParentStyle()
override;
81 virtual void SAL_CALL setParentStyle(
const OUString& aParentStyle )
override;
84 virtual OUString SAL_CALL getName()
override;
85 virtual void SAL_CALL setName(
const OUString&
aName )
override;
88 virtual Any SAL_CALL getByName(
const OUString&
aName )
override;
89 virtual Sequence< OUString > SAL_CALL getElementNames()
override;
90 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override;
93 virtual css::uno::Type SAL_CALL getElementType()
override;
94 virtual sal_Bool SAL_CALL hasElements()
override;
97 virtual sal_Int32 SAL_CALL getCount()
override ;
98 virtual Any SAL_CALL getByIndex( sal_Int32
Index )
override;
101 virtual void SAL_CALL replaceByIndex( sal_Int32
Index,
const Any& Element )
override;
104 virtual void SAL_CALL replaceByName(
const OUString&
aName,
const Any& aElement )
override;
107 virtual Reference<XPropertySetInfo> SAL_CALL getPropertySetInfo()
override;
108 virtual void SAL_CALL
setPropertyValue(
const OUString& aPropertyName,
const Any& aValue )
override;
110 virtual void SAL_CALL addPropertyChangeListener(
const OUString& aPropertyName,
const Reference<XPropertyChangeListener>& xListener )
override;
111 virtual void SAL_CALL removePropertyChangeListener(
const OUString& aPropertyName,
const Reference<XPropertyChangeListener>& aListener )
override;
112 virtual void SAL_CALL addVetoableChangeListener(
const OUString& PropertyName,
const Reference<XVetoableChangeListener>& aListener )
override;
113 virtual void SAL_CALL removeVetoableChangeListener(
const OUString& PropertyName,
const Reference<XVetoableChangeListener>&aListener )
override;
116 virtual sal_Bool SAL_CALL isModified()
override;
117 virtual void SAL_CALL setModified(
sal_Bool bModified )
override;
120 virtual void SAL_CALL addModifyListener(
const Reference< XModifyListener >& aListener )
override;
121 virtual void SAL_CALL removeModifyListener(
const Reference< XModifyListener >& aListener )
override;
124 virtual void SAL_CALL modified(
const css::lang::EventObject&
aEvent )
override;
125 virtual void SAL_CALL disposing(
const css::lang::EventObject&
Source )
override;
127 void notifyModifyListener();
128 void resetUserDefined();
131 virtual void disposing(std::unique_lock<std::mutex>& aGuard)
override;
147class TableDesignFamily :
public ::cppu::WeakImplHelper< XNameContainer, XNamed, XIndexAccess, XSingleServiceFactory, XServiceInfo, XComponent, XPropertySet, form::XReset >
156 virtual OUString SAL_CALL getName( )
override;
157 virtual void SAL_CALL setName(
const OUString&
aName )
override;
160 virtual Any SAL_CALL getByName(
const OUString&
aName )
override;
161 virtual Sequence< OUString > SAL_CALL getElementNames()
override;
162 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override;
165 virtual Type SAL_CALL getElementType()
override;
166 virtual sal_Bool SAL_CALL hasElements()
override;
169 virtual sal_Int32 SAL_CALL getCount()
override ;
170 virtual Any SAL_CALL getByIndex( sal_Int32
Index )
override;
173 virtual void SAL_CALL insertByName(
const OUString&
aName,
const Any& aElement )
override;
174 virtual void SAL_CALL removeByName(
const OUString&
Name )
override;
177 virtual void SAL_CALL replaceByName(
const OUString&
aName,
const Any& aElement )
override;
180 virtual Reference< XInterface > SAL_CALL
createInstance( )
override;
181 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments(
const Sequence< Any >&
aArguments )
override;
184 virtual void SAL_CALL
dispose( )
override;
185 virtual void SAL_CALL addEventListener(
const Reference< XEventListener >& xListener )
override;
186 virtual void SAL_CALL removeEventListener(
const Reference< XEventListener >& aListener )
override;
189 virtual Reference<XPropertySetInfo> SAL_CALL getPropertySetInfo()
override;
190 virtual void SAL_CALL
setPropertyValue(
const OUString& aPropertyName,
const Any& aValue )
override;
192 virtual void SAL_CALL addPropertyChangeListener(
const OUString& aPropertyName,
const Reference<XPropertyChangeListener>& xListener )
override;
193 virtual void SAL_CALL removePropertyChangeListener(
const OUString& aPropertyName,
const Reference<XPropertyChangeListener>& aListener )
override;
194 virtual void SAL_CALL addVetoableChangeListener(
const OUString& PropertyName,
const Reference<XVetoableChangeListener>& aListener )
override;
195 virtual void SAL_CALL removeVetoableChangeListener(
const OUString& PropertyName,
const Reference<XVetoableChangeListener>&aListener )
override;
198 virtual void SAL_CALL reset()
override;
199 virtual void SAL_CALL addResetListener(
const Reference<form::XResetListener>& aListener )
override;
200 virtual void SAL_CALL removeResetListener(
const Reference<form::XResetListener>& aListener )
override;
207TableDesignStyle::TableDesignStyle()
233OUString SAL_CALL TableDesignStyle::getImplementationName()
235 return "TableDesignStyle";
238sal_Bool SAL_CALL TableDesignStyle::supportsService(
const OUString& ServiceName )
243Sequence< OUString > SAL_CALL TableDesignStyle::getSupportedServiceNames()
245 return {
"com.sun.star.style.Style" };
249sal_Bool SAL_CALL TableDesignStyle::isUserDefined()
254void TableDesignStyle::resetUserDefined()
259sal_Bool SAL_CALL TableDesignStyle::isInUse()
261 std::unique_lock aGuard( m_aMutex );
265 while ( it.hasMoreElements() )
267 SdrTableObjImpl* pUser =
dynamic_cast< SdrTableObjImpl*
>( it.next().get() );
268 if( pUser && pUser->isInUse() )
276OUString SAL_CALL TableDesignStyle::getParentStyle()
282void SAL_CALL TableDesignStyle::setParentStyle(
const OUString& )
290OUString SAL_CALL TableDesignStyle::getName()
296void SAL_CALL TableDesignStyle::setName(
const OUString& rName )
305Any SAL_CALL TableDesignStyle::getByName(
const OUString& rName )
309 CellStyleNameMap::const_iterator iter = rMap.find( rName );
310 if( iter == rMap.end() )
311 throw NoSuchElementException();
317Sequence< OUString > SAL_CALL TableDesignStyle::getElementNames()
323sal_Bool SAL_CALL TableDesignStyle::hasByName(
const OUString& rName )
327 CellStyleNameMap::const_iterator iter = rMap.find( rName );
328 return iter != rMap.end();
335Type SAL_CALL TableDesignStyle::getElementType()
341sal_Bool SAL_CALL TableDesignStyle::hasElements()
350sal_Int32 SAL_CALL TableDesignStyle::getCount()
356Any SAL_CALL TableDesignStyle::getByIndex( sal_Int32
Index )
359 throw IndexOutOfBoundsException();
361 std::unique_lock aGuard( m_aMutex );
368void SAL_CALL TableDesignStyle::replaceByIndex( sal_Int32
Index,
const Any& aElement )
371 throw IndexOutOfBoundsException();
374 auto iter = std::find_if(rMap.begin(), rMap.end(),
375 [&
Index](
const auto& item) { return Index == item.second; });
376 if (iter != rMap.end())
377 replaceByName(iter->first, aElement);
384void SAL_CALL TableDesignStyle::replaceByName(
const OUString& rName,
const Any& aElement )
387 CellStyleNameMap::const_iterator iter = rMap.find( rName );
388 if( iter == rMap.end() )
389 throw NoSuchElementException();
392 Reference< XStyle > xNewStyle;
393 if( !(aElement >>= xNewStyle) )
394 throw IllegalArgumentException();
396 const sal_Int32
nIndex = (*iter).second;
398 std::unique_lock aGuard( m_aMutex );
402 if( xNewStyle == xOldStyle )
405 Reference< XModifyListener > xListener(
this );
408 Reference< XModifyBroadcaster > xOldBroadcaster( xOldStyle, UNO_QUERY );
409 if( xOldBroadcaster.is() )
410 xOldBroadcaster->removeModifyListener( xListener );
413 Reference< XModifyBroadcaster > xNewBroadcaster( xNewStyle, UNO_QUERY );
414 if( xNewBroadcaster.is() )
415 xNewBroadcaster->addModifyListener( xListener );
417 if (xNewStyle && xNewStyle->isUserDefined())
427void TableDesignStyle::disposing(std::unique_lock<std::mutex>& aGuard)
433 Reference<XModifyBroadcaster> xBroadcaster(rCellStyle, UNO_QUERY);
435 xBroadcaster->removeModifyListener(
this);
442Reference<XPropertySetInfo> TableDesignStyle::getPropertySetInfo()
447void TableDesignStyle::setPropertyValue(
const OUString&,
const Any& )
451Any TableDesignStyle::getPropertyValue(
const OUString& PropertyName )
453 if (PropertyName !=
"IsPhysical")
454 throw UnknownPropertyException(
"unknown property: " + PropertyName, getXWeak());
459void TableDesignStyle::addPropertyChangeListener(
const OUString&,
const Reference<XPropertyChangeListener>& )
463void TableDesignStyle::removePropertyChangeListener(
const OUString&,
const Reference<XPropertyChangeListener>& )
467void TableDesignStyle::addVetoableChangeListener(
const OUString&,
const Reference<XVetoableChangeListener>& )
471void TableDesignStyle::removeVetoableChangeListener(
const OUString&,
const Reference<XVetoableChangeListener>& )
477sal_Bool TableDesignStyle::isModified()
482void TableDesignStyle::setModified(
sal_Bool bModified )
485 notifyModifyListener();
492void SAL_CALL TableDesignStyle::addModifyListener(
const Reference< XModifyListener >& xListener )
494 std::unique_lock aGuard( m_aMutex );
498 EventObject aEvt( getXWeak() );
499 xListener->disposing( aEvt );
508void SAL_CALL TableDesignStyle::removeModifyListener(
const Reference< XModifyListener >& xListener )
510 std::unique_lock aGuard( m_aMutex );
515void TableDesignStyle::notifyModifyListener()
517 std::unique_lock aGuard( m_aMutex );
521 EventObject aEvt( getXWeak() );
523 [&] (Reference<XModifyListener>
const& xListener)
524 {
return xListener->modified(aEvt); });
533void SAL_CALL TableDesignStyle::modified(
const css::lang::EventObject& )
535 notifyModifyListener();
539void SAL_CALL TableDesignStyle::disposing(
const css::lang::EventObject& )
548OUString SAL_CALL TableDesignFamily::getImplementationName()
550 return "TableDesignFamily";
553sal_Bool SAL_CALL TableDesignFamily::supportsService(
const OUString& ServiceName )
558Sequence< OUString > SAL_CALL TableDesignFamily::getSupportedServiceNames()
560 return {
"com.sun.star.style.StyleFamily" };
564OUString SAL_CALL TableDesignFamily::getName()
569void SAL_CALL TableDesignFamily::setName(
const OUString& )
574Any SAL_CALL TableDesignFamily::getByName(
const OUString& rName )
579 [&rName](
const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; });
581 return Any( (*iter) );
583 throw NoSuchElementException();
587Sequence< OUString > SAL_CALL TableDesignFamily::getElementNames()
591 Sequence< OUString > aRet(
maDesigns.size() );
592 OUString* pNames = aRet.getArray();
595 *pNames++ = rpStyle->getName();
601sal_Bool SAL_CALL TableDesignFamily::hasByName(
const OUString& aName )
606 [&aName](
const Reference<XStyle>& rpStyle) { return rpStyle->getName() == aName; });
613Type SAL_CALL TableDesignFamily::getElementType()
619sal_Bool SAL_CALL TableDesignFamily::hasElements()
630sal_Int32 SAL_CALL TableDesignFamily::getCount()
634 return sal::static_int_cast< sal_Int32 >(
maDesigns.size() );
638Any SAL_CALL TableDesignFamily::getByIndex( sal_Int32
Index )
645 throw IndexOutOfBoundsException();
652void SAL_CALL TableDesignFamily::insertByName(
const OUString& rName,
const Any& rElement )
656 Reference< XStyle > xStyle( rElement, UNO_QUERY );
658 throw IllegalArgumentException();
660 xStyle->setName( rName );
662 [&rName](
const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; }))
663 throw ElementExistException();
669void SAL_CALL TableDesignFamily::removeByName(
const OUString& rName )
674 [&rName](
const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; });
677 Reference<XComponent> xComponent(*iter, UNO_QUERY);
679 xComponent->dispose();
684 throw NoSuchElementException();
691void SAL_CALL TableDesignFamily::replaceByName(
const OUString& rName,
const Any& aElement )
695 Reference< XStyle > xStyle( aElement, UNO_QUERY );
697 throw IllegalArgumentException();
700 [&rName](
const Reference<XStyle>& rpStyle) { return rpStyle->getName() == rName; });
703 if (!(*iter)->isUserDefined())
704 static_cast<TableDesignStyle*
>(xStyle.get())->resetUserDefined();
706 Reference<XComponent> xComponent(*iter, UNO_QUERY);
708 xComponent->dispose();
710 xStyle->setName( rName );
714 throw NoSuchElementException();
721Reference< XInterface > SAL_CALL TableDesignFamily::createInstance()
723 return Reference< XInterface >(
static_cast< XStyle*
>(
new TableDesignStyle ) );
727Reference< XInterface > SAL_CALL TableDesignFamily::createInstanceWithArguments(
const Sequence< Any >& )
736void SAL_CALL TableDesignFamily::dispose( )
741 for(
const auto& rStyle : aDesigns )
743 Reference< XComponent > xComp( rStyle, UNO_QUERY );
750void SAL_CALL TableDesignFamily::addEventListener(
const Reference< XEventListener >& )
755void SAL_CALL TableDesignFamily::removeEventListener(
const Reference< XEventListener >& )
763Reference<XPropertySetInfo> TableDesignFamily::getPropertySetInfo()
765 OSL_FAIL(
"###unexpected!" );
766 return Reference<XPropertySetInfo>();
770void TableDesignFamily::setPropertyValue(
const OUString& ,
const Any& )
772 OSL_FAIL(
"###unexpected!" );
776Any TableDesignFamily::getPropertyValue(
const OUString& PropertyName )
778 if ( PropertyName !=
"DisplayName" )
780 throw UnknownPropertyException(
"unknown property: " + PropertyName, getXWeak() );
784 return Any( sDisplayName );
788void TableDesignFamily::addPropertyChangeListener(
const OUString& ,
const Reference<XPropertyChangeListener>& )
790 OSL_FAIL(
"###unexpected!" );
794void TableDesignFamily::removePropertyChangeListener(
const OUString& ,
const Reference<XPropertyChangeListener>& )
796 OSL_FAIL(
"###unexpected!" );
800void TableDesignFamily::addVetoableChangeListener(
const OUString& ,
const Reference<XVetoableChangeListener>& )
802 OSL_FAIL(
"###unexpected!" );
806void TableDesignFamily::removeVetoableChangeListener(
const OUString& ,
const Reference<XVetoableChangeListener>& )
808 OSL_FAIL(
"###unexpected!" );
813void TableDesignFamily::reset()
817 auto aStyle =
static_cast<TableDesignStyle*
>(aDesign.get());
818 aStyle->resetUserDefined();
819 aStyle->setModified(
false);
823void TableDesignFamily::addResetListener(
const Reference<form::XResetListener>& )
827void TableDesignFamily::removeResetListener(
const Reference<form::XResetListener>& )
833 return new TableDesignFamily;
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
void forEach(std::unique_lock< std::mutex > &rGuard, FuncT const &func) const
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
css::uno::Type const & get()
OUString SvxResId(TranslateId aId)
Sequence< PropertyValue > aArguments
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
const sal_Int32 background_style
::comphelper::WeakComponentImplHelper< XStyle, XNameReplace, XServiceInfo, XIndexReplace, XModifiable, XModifyListener, XPropertySet > TableDesignStyleBase
const sal_Int32 style_count
const sal_Int32 last_column_style
std::map< OUString, sal_Int32 > CellStyleNameMap
const sal_Int32 first_column_style
const sal_Int32 odd_columns_style
const sal_Int32 body_style
std::vector< Reference< XStyle > > TableDesignStyleVector
const sal_Int32 even_rows_style
const sal_Int32 first_row_style
const sal_Int32 last_row_style
Reference< XNameAccess > CreateTableDesignFamily()
const sal_Int32 even_columns_style
const sal_Int32 odd_rows_style
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
HashMap_OWString_Interface aMap
comphelper::OInterfaceContainerHelper4< XModifyListener > maModifyListeners
Reference< XStyle > maCellStyles[style_count]
TableDesignStyleVector maDesigns
std::map< OUString, sal_Int32 > CellStyleNameMap