summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-09-06 14:49:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-09-06 16:11:40 +0200
commitde42529ca9107b24b6367b40801300416d4a51a1 (patch)
treec8795037968bbb4911ddc7076baabe72f2d23487 /svx
parent25664e5da6b5196f5969188bce06e85730ceeaf2 (diff)
replace svx::PropertyValueProvider with simpler implementation
it was not actually doing much besides managing the listener list, so just use a regular listener list implementation. Registering was unnecessary as well, we can use getPropertyValue() to retrieve the current value. Change-Id: I53ae496e07ff028b12646668b134ffcab18484aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156619 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/source/svdraw/svdobj.cxx17
-rw-r--r--svx/source/unodraw/shapepropertynotifier.cxx142
-rw-r--r--svx/source/unodraw/unoshape.cxx79
4 files changed, 29 insertions, 210 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 6e7466541427..c4ba58048f4b 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -441,7 +441,6 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/toolbars/fontworkbar \
svx/source/uitest/sdrobject \
svx/source/unodraw/gluepts \
- svx/source/unodraw/shapepropertynotifier \
svx/source/unodraw/SvxXTextColumns \
svx/source/unodraw/tableshape \
svx/source/unodraw/unobrushitemhelper \
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index dc9e36a008ce..c0d4c15d0096 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -51,7 +51,6 @@
#include <vcl/ptrstyle.hxx>
#include <vector>
-#include <svx/shapepropertynotifier.hxx>
#include <svx/svdotable.hxx>
#include <svx/sdr/contact/displayinfo.hxx>
@@ -2810,10 +2809,10 @@ void SdrObject::SendUserCall(SdrUserCallType eUserCall, const tools::Rectangle&
switch ( eUserCall )
{
case SdrUserCallType::Resize:
- notifyShapePropertyChange( svx::ShapePropertyProviderId::Size );
+ notifyShapePropertyChange( "Size" );
[[fallthrough]]; // RESIZE might also imply a change of the position
case SdrUserCallType::MoveOnly:
- notifyShapePropertyChange( svx::ShapePropertyProviderId::Position );
+ notifyShapePropertyChange( "Position" );
break;
default:
// not interested in
@@ -2953,21 +2952,13 @@ css::uno::Reference< css::drawing::XShape > SdrObject::getUnoShape()
return xShape;
}
-void SdrObject::notifyShapePropertyChange( const svx::ShapePropertyProviderId _eProperty ) const
+void SdrObject::notifyShapePropertyChange( const OUString& rPropName ) const
{
DBG_TESTSOLARMUTEX();
SvxShape* pSvxShape = const_cast< SdrObject* >( this )->getSvxShape();
if ( pSvxShape )
- return pSvxShape->notifyPropertyChange( _eProperty );
-}
-
-void SdrObject::registerProvider( const svx::ShapePropertyProviderId _eProperty, std::unique_ptr<svx::PropertyValueProvider> provider )
-{
- DBG_TESTSOLARMUTEX();
-
- SvxShape* pSvxShape = getSvxShape();
- return pSvxShape->registerProvider( _eProperty, std::move(provider) );
+ return pSvxShape->notifyPropertyChange( rPropName );
}
// transformation interface for StarOfficeAPI. This implements support for
diff --git a/svx/source/unodraw/shapepropertynotifier.cxx b/svx/source/unodraw/shapepropertynotifier.cxx
deleted file mode 100644
index a1b1ad07a626..000000000000
--- a/svx/source/unodraw/shapepropertynotifier.cxx
+++ /dev/null
@@ -1,142 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-
-#include <svx/shapepropertynotifier.hxx>
-
-#include <com/sun/star/beans/XPropertySet.hpp>
-
-#include <cppuhelper/weak.hxx>
-#include <comphelper/diagnose_ex.hxx>
-
-namespace
-{
-
-}
-
-
-namespace svx
-{
-
-
- using ::com::sun::star::uno::Reference;
- using ::com::sun::star::uno::UNO_QUERY_THROW;
- using ::com::sun::star::uno::Exception;
- using ::com::sun::star::uno::Any;
- using ::com::sun::star::beans::PropertyChangeEvent;
- using ::com::sun::star::beans::XPropertyChangeListener;
- using ::com::sun::star::lang::EventObject;
- using ::com::sun::star::beans::XPropertySet;
-
- PropertyValueProvider::~PropertyValueProvider()
- {
- }
-
- //= PropertyValueProvider
-
-
- const OUString & PropertyValueProvider::getPropertyName() const
- {
- return m_sPropertyName;
- }
-
-
- void PropertyValueProvider::getCurrentValue( Any& _out_rValue ) const
- {
- Reference< XPropertySet > xContextProps( const_cast< PropertyValueProvider* >( this )->m_rContext, UNO_QUERY_THROW );
- _out_rValue = xContextProps->getPropertyValue( getPropertyName() );
- }
-
- PropertyChangeNotifier::PropertyChangeNotifier( ::cppu::OWeakObject& _rOwner )
- :m_rContext( _rOwner )
- {
- }
-
- PropertyChangeNotifier::~PropertyChangeNotifier()
- {
- }
-
- void PropertyChangeNotifier::registerProvider(const ShapePropertyProviderId _eProperty, std::unique_ptr<PropertyValueProvider> _rProvider)
- {
- assert( _rProvider && "NULL factory not allowed." );
-
- assert( ! m_aProviders[_eProperty] &&
- "PropertyChangeNotifier::registerProvider: factory for this ID already present!" );
-
- m_aProviders[ _eProperty ] = std::move(_rProvider);
- }
-
- void PropertyChangeNotifier::notifyPropertyChange( std::unique_lock<std::mutex>& rGuard, const ShapePropertyProviderId _eProperty ) const
- {
- auto & provPos = m_aProviders[ _eProperty ];
- OSL_ENSURE( provPos, "PropertyChangeNotifier::notifyPropertyChange: no factory!" );
- if (!provPos)
- return;
-
- const OUString & sPropertyName( provPos->getPropertyName() );
-
- ::comphelper::OInterfaceContainerHelper4<XPropertyChangeListener>* pPropListeners = m_aPropertyChangeListeners.getContainer( rGuard, sPropertyName );
- ::comphelper::OInterfaceContainerHelper4<XPropertyChangeListener>* pAllListeners = m_aPropertyChangeListeners.getContainer( rGuard, OUString() );
- if ( !pPropListeners && !pAllListeners )
- return;
-
- try
- {
- PropertyChangeEvent aEvent;
- aEvent.Source = m_rContext;
- // Handle/OldValue not supported
- aEvent.PropertyName = provPos->getPropertyName();
- provPos->getCurrentValue( aEvent.NewValue );
-
- if ( pPropListeners )
- pPropListeners->notifyEach( rGuard, &XPropertyChangeListener::propertyChange, aEvent );
- if ( pAllListeners )
- pAllListeners->notifyEach( rGuard, &XPropertyChangeListener::propertyChange, aEvent );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION("svx");
- }
- }
-
-
- void PropertyChangeNotifier::addPropertyChangeListener( std::unique_lock<std::mutex>& rGuard, const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
- {
- m_aPropertyChangeListeners.addInterface( rGuard, _rPropertyName, _rxListener );
- }
-
-
- void PropertyChangeNotifier::removePropertyChangeListener( std::unique_lock<std::mutex>& rGuard, const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
- {
- m_aPropertyChangeListeners.removeInterface( rGuard, _rPropertyName, _rxListener );
- }
-
-
- void PropertyChangeNotifier::disposing(std::unique_lock<std::mutex>& rGuard)
- {
- EventObject aEvent;
- aEvent.Source = m_rContext;
- m_aPropertyChangeListeners.disposeAndClear( rGuard, aEvent );
- }
-
-
-}
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index 6bd355391301..8b3155ad2382 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -29,10 +29,10 @@
#include <editeng/unotext.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdoole2.hxx>
-#include <svx/shapepropertynotifier.hxx>
#include <comphelper/interfacecontainer3.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/servicehelper.hxx>
+#include <comphelper/multiinterfacecontainer4.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/gfxlink.hxx>
#include <vcl/virdev.hxx>
@@ -106,7 +106,6 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
-using svx::PropertyValueProvider;
class GDIMetaFile;
@@ -126,51 +125,18 @@ struct SvxShapeImpl
// for xComponent
::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> maDisposeListeners;
- svx::PropertyChangeNotifier maPropertyNotifier;
+ ::comphelper::OMultiTypeInterfaceContainerHelperVar4<OUString, css::beans::XPropertyChangeListener> maPropertyChangeListeners;
- SvxShapeImpl( SvxShape& _rAntiImpl )
+ SvxShapeImpl()
:mnObjId( SdrObjKind::NONE )
,mpMaster( nullptr )
,mbDisposing( false )
- ,maPropertyNotifier( _rAntiImpl )
{
}
};
namespace {
-class ShapePositionProvider : public PropertyValueProvider
-{
-public:
- static constexpr OUStringLiteral sPosition = u"Position";
- explicit ShapePositionProvider( SvxShape& _shape )
- :PropertyValueProvider( _shape, sPosition )
- {
- }
-
-protected:
- virtual void getCurrentValue( Any& _out_rCurrentValue ) const override
- {
- _out_rCurrentValue <<= static_cast< SvxShape& >( getContext() ).getPosition();
- }
-};
-
-
-class ShapeSizeProvider : public PropertyValueProvider
-{
-public:
- static constexpr OUStringLiteral sSize = u"Size";
- explicit ShapeSizeProvider( SvxShape& _shape )
- :PropertyValueProvider( _shape, sSize )
- {
- }
-
-protected:
- virtual void getCurrentValue( Any& _out_rCurrentValue ) const override
- {
- _out_rCurrentValue <<= static_cast< SvxShape& >( getContext() ).getSize();
- }
-};
/// Calculates what scaling factor will be used for autofit text scaling of this shape.
double GetTextFitToSizeScale(SdrObject* pObject)
@@ -194,7 +160,7 @@ double GetTextFitToSizeScale(SdrObject* pObject)
SvxShape::SvxShape( SdrObject* pObject )
: maSize(100,100)
-, mpImpl( new SvxShapeImpl( *this ) )
+, mpImpl( new SvxShapeImpl )
, mbIsMultiPropertyCall(false)
, mpPropSet(getSvxMapProvider().GetPropertySet(SVXMAP_SHAPE, SdrObject::GetGlobalDrawObjectItemPool()))
, maPropMapEntries(getSvxMapProvider().GetMap(SVXMAP_SHAPE))
@@ -207,7 +173,7 @@ SvxShape::SvxShape( SdrObject* pObject )
SvxShape::SvxShape( SdrObject* pObject, o3tl::span<const SfxItemPropertyMapEntry> pEntries, const SvxItemPropertySet* pPropertySet )
: maSize(100,100)
-, mpImpl( new SvxShapeImpl( *this ) )
+, mpImpl( new SvxShapeImpl )
, mbIsMultiPropertyCall(false)
, mpPropSet(pPropertySet)
, maPropMapEntries(pEntries)
@@ -289,24 +255,29 @@ sal_Int64 SAL_CALL SvxShape::getSomething( const css::uno::Sequence< sal_Int8 >&
}
-void SvxShape::notifyPropertyChange(svx::ShapePropertyProviderId eProp)
+void SvxShape::notifyPropertyChange(const OUString& rPropName)
{
std::unique_lock g(m_aMutex);
- mpImpl->maPropertyNotifier.notifyPropertyChange(g, eProp);
-}
-
-void SvxShape::registerProvider(svx::ShapePropertyProviderId eProp, std::unique_ptr<svx::PropertyValueProvider> provider)
-{
- mpImpl->maPropertyNotifier.registerProvider(eProp, std::move(provider));
+ comphelper::OInterfaceContainerHelper4<beans::XPropertyChangeListener>* pPropListeners =
+ mpImpl->maPropertyChangeListeners.getContainer( g, rPropName );
+ comphelper::OInterfaceContainerHelper4<beans::XPropertyChangeListener>* pAllListeners =
+ mpImpl->maPropertyChangeListeners.getContainer( g, OUString() );
+ if (pPropListeners || pAllListeners)
+ {
+ // Handle/OldValue not supported
+ beans::PropertyChangeEvent aEvt;
+ aEvt.Source = static_cast<cppu::OWeakObject*>(this);
+ aEvt.PropertyName = rPropName;
+ aEvt.NewValue = getPropertyValue(rPropName);
+ if (pPropListeners)
+ pPropListeners->notifyEach( g, &beans::XPropertyChangeListener::propertyChange, aEvt );
+ if (pAllListeners)
+ pAllListeners->notifyEach( g, &beans::XPropertyChangeListener::propertyChange, aEvt );
+ }
}
void SvxShape::impl_construct()
{
- mpImpl->maPropertyNotifier.registerProvider( svx::ShapePropertyProviderId::Position,
- std::make_unique<ShapePositionProvider>( *this ) );
- mpImpl->maPropertyNotifier.registerProvider( svx::ShapePropertyProviderId::Size,
- std::make_unique<ShapeSizeProvider>( *this ) );
-
if ( HasSdrObject() )
{
StartListening(GetSdrObject()->getSdrModelFromSdrObject());
@@ -1209,7 +1180,7 @@ void SAL_CALL SvxShape::dispose()
lang::EventObject aEvt;
aEvt.Source = *static_cast<OWeakAggObject*>(this);
mpImpl->maDisposeListeners.disposeAndClear(g, aEvt);
- mpImpl->maPropertyNotifier.disposing(g);
+ mpImpl->maPropertyChangeListeners.disposeAndClear(g, aEvt);
rtl::Reference<SdrObject> pObject = mxSdrObject;
if (!pObject)
@@ -1276,14 +1247,14 @@ Reference< beans::XPropertySetInfo > const &
void SAL_CALL SvxShape::addPropertyChangeListener( const OUString& _propertyName, const Reference< beans::XPropertyChangeListener >& _listener )
{
std::unique_lock g(m_aMutex);
- mpImpl->maPropertyNotifier.addPropertyChangeListener( g, _propertyName, _listener );
+ mpImpl->maPropertyChangeListeners.addInterface( g, _propertyName, _listener );
}
void SAL_CALL SvxShape::removePropertyChangeListener( const OUString& _propertyName, const Reference< beans::XPropertyChangeListener >& _listener )
{
std::unique_lock g(m_aMutex);
- mpImpl->maPropertyNotifier.removePropertyChangeListener( g, _propertyName, _listener );
+ mpImpl->maPropertyChangeListeners.removeInterface( g, _propertyName, _listener );
}