LibreOffice Module svx (master) 1
shapepropertynotifier.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22
23#include <com/sun/star/beans/XPropertySet.hpp>
24
25#include <cppuhelper/weak.hxx>
26#include <tools/diagnose_ex.h>
27
28namespace
29{
30
31}
32
33
34namespace svx
35{
36
37
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::UNO_QUERY_THROW;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::beans::PropertyChangeEvent;
43 using ::com::sun::star::beans::XPropertyChangeListener;
44 using ::com::sun::star::lang::EventObject;
46
48 {
49 }
50
51 //= PropertyValueProvider
52
53
55 {
56 return m_sPropertyName;
57 }
58
59
60 void PropertyValueProvider::getCurrentValue( Any& _out_rValue ) const
61 {
62 Reference< XPropertySet > xContextProps( const_cast< PropertyValueProvider* >( this )->m_rContext, UNO_QUERY_THROW );
63 _out_rValue = xContextProps->getPropertyValue( getPropertyName() );
64 }
65
67 :m_rContext( _rOwner )
68 ,m_aPropertyChangeListeners( _rMutex )
69 {
70 }
71
73 {
74 }
75
76 void PropertyChangeNotifier::registerProvider(const ShapePropertyProviderId _eProperty, std::unique_ptr<PropertyValueProvider> _rProvider)
77 {
78 assert( _rProvider && "NULL factory not allowed." );
79
80 assert( ! m_aProviders[_eProperty] &&
81 "PropertyChangeNotifier::registerProvider: factory for this ID already present!" );
82
83 m_aProviders[ _eProperty ] = std::move(_rProvider);
84 }
85
87 {
88 auto & provPos = m_aProviders[ _eProperty ];
89 OSL_ENSURE( provPos, "PropertyChangeNotifier::notifyPropertyChange: no factory!" );
90 if (!provPos)
91 return;
92
93 const OUString & sPropertyName( provPos->getPropertyName() );
94
97 if ( !pPropListeners && !pAllListeners )
98 return;
99
100 try
101 {
102 PropertyChangeEvent aEvent;
103 aEvent.Source = m_rContext;
104 // Handle/OldValue not supported
105 aEvent.PropertyName = provPos->getPropertyName();
106 provPos->getCurrentValue( aEvent.NewValue );
107
108 if ( pPropListeners )
109 pPropListeners->notifyEach( &XPropertyChangeListener::propertyChange, aEvent );
110 if ( pAllListeners )
111 pAllListeners->notifyEach( &XPropertyChangeListener::propertyChange, aEvent );
112 }
113 catch( const Exception& )
114 {
116 }
117 }
118
119
120 void PropertyChangeNotifier::addPropertyChangeListener( const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
121 {
122 m_aPropertyChangeListeners.addInterface( _rPropertyName, _rxListener );
123 }
124
125
126 void PropertyChangeNotifier::removePropertyChangeListener( const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
127 {
128 m_aPropertyChangeListeners.removeInterface( _rPropertyName, _rxListener );
129 }
130
131
133 {
134 EventObject aEvent;
135 aEvent.Source = m_rContext;
137 }
138
139
140}
141
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
sal_Int32 addInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
sal_Int32 removeInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
void disposeAndClear(const css::lang::EventObject &rEvt)
OInterfaceContainerHelper3< listener > * getContainer(const key &rKey) const
void addPropertyChangeListener(const OUString &_rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &_rxListener)
PropertyChangeNotifier(::cppu::OWeakObject &_rOwner, ::osl::Mutex &_rMutex)
constructs a notifier instance
o3tl::enumarray< ShapePropertyProviderId, std::unique_ptr< PropertyValueProvider > > m_aProviders
void disposing()
is called to dispose the instance
void removePropertyChangeListener(const OUString &_rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &_rxListener)
void registerProvider(const ShapePropertyProviderId _eProperty, std::unique_ptr< PropertyValueProvider > _rProvider)
registers an PropertyValueProvider
comphelper::OMultiTypeInterfaceContainerHelperVar3< css::beans::XPropertyChangeListener, OUString > m_aPropertyChangeListeners
void notifyPropertyChange(const ShapePropertyProviderId _eProperty) const
notifies changes in the given property to all registered listeners
Default provider for a property value.
const OUString & getPropertyName() const
returns the name of the property which this provider is responsible for
::cppu::OWeakObject & m_rContext
virtual void getCurrentValue(css::uno::Any &_out_rValue) const
returns the current value of the property which the provider is responsible for
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
class SAL_NO_VTABLE XPropertySet
Definition: xmlexchg.hxx:28
const Reference< XComponentContext > & m_rContext