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>
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 {
69 }
70
72 {
73 }
74
75 void PropertyChangeNotifier::registerProvider(const ShapePropertyProviderId _eProperty, std::unique_ptr<PropertyValueProvider> _rProvider)
76 {
77 assert( _rProvider && "NULL factory not allowed." );
78
79 assert( ! m_aProviders[_eProperty] &&
80 "PropertyChangeNotifier::registerProvider: factory for this ID already present!" );
81
82 m_aProviders[ _eProperty ] = std::move(_rProvider);
83 }
84
85 void PropertyChangeNotifier::notifyPropertyChange( std::unique_lock<std::mutex>& rGuard, const ShapePropertyProviderId _eProperty ) const
86 {
87 auto & provPos = m_aProviders[ _eProperty ];
88 OSL_ENSURE( provPos, "PropertyChangeNotifier::notifyPropertyChange: no factory!" );
89 if (!provPos)
90 return;
91
92 const OUString & sPropertyName( provPos->getPropertyName() );
93
96 if ( !pPropListeners && !pAllListeners )
97 return;
98
99 try
100 {
101 PropertyChangeEvent aEvent;
102 aEvent.Source = m_rContext;
103 // Handle/OldValue not supported
104 aEvent.PropertyName = provPos->getPropertyName();
105 provPos->getCurrentValue( aEvent.NewValue );
106
107 if ( pPropListeners )
108 pPropListeners->notifyEach( rGuard, &XPropertyChangeListener::propertyChange, aEvent );
109 if ( pAllListeners )
110 pAllListeners->notifyEach( rGuard, &XPropertyChangeListener::propertyChange, aEvent );
111 }
112 catch( const Exception& )
113 {
115 }
116 }
117
118
119 void PropertyChangeNotifier::addPropertyChangeListener( std::unique_lock<std::mutex>& rGuard, const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
120 {
121 m_aPropertyChangeListeners.addInterface( rGuard, _rPropertyName, _rxListener );
122 }
123
124
125 void PropertyChangeNotifier::removePropertyChangeListener( std::unique_lock<std::mutex>& rGuard, const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
126 {
127 m_aPropertyChangeListeners.removeInterface( rGuard, _rPropertyName, _rxListener );
128 }
129
130
131 void PropertyChangeNotifier::disposing(std::unique_lock<std::mutex>& rGuard)
132 {
133 EventObject aEvent;
134 aEvent.Source = m_rContext;
136 }
137
138
139}
140
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
void notifyEach(std::unique_lock< std::mutex > &rGuard, void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event) const
sal_Int32 removeInterface(::std::unique_lock<::std::mutex > &rGuard, const key &rKey, const css::uno::Reference< listener > &rListener)
sal_Int32 addInterface(::std::unique_lock<::std::mutex > &rGuard, const key &rKey, const css::uno::Reference< listener > &rListener)
void disposeAndClear(std::unique_lock< std::mutex > &rGuard, const css::lang::EventObject &rEvt)
OInterfaceContainerHelper4< listener > * getContainer(std::unique_lock< std::mutex > &rGuard, const key &rKey) const
void disposing(std::unique_lock< std::mutex > &rGuard)
is called to dispose the instance
void addPropertyChangeListener(std::unique_lock< std::mutex > &rGuard, const OUString &_rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &_rxListener)
comphelper::OMultiTypeInterfaceContainerHelperVar4< OUString, css::beans::XPropertyChangeListener > m_aPropertyChangeListeners
void notifyPropertyChange(std::unique_lock< std::mutex > &rGuard, const ShapePropertyProviderId _eProperty) const
notifies changes in the given property to all registered listeners
o3tl::enumarray< ShapePropertyProviderId, std::unique_ptr< PropertyValueProvider > > m_aProviders
void removePropertyChangeListener(std::unique_lock< std::mutex > &rGuard, const OUString &_rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &_rxListener)
PropertyChangeNotifier(::cppu::OWeakObject &_rOwner)
constructs a notifier instance
void registerProvider(const ShapePropertyProviderId _eProperty, std::unique_ptr< PropertyValueProvider > _rProvider)
registers an PropertyValueProvider
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:29
const Reference< XComponentContext > & m_rContext