1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SHAPEPROPERTYNOTIFIER_HXX
21 #define INCLUDED_SVX_SHAPEPROPERTYNOTIFIER_HXX
23 #include <svx/svxdllapi.h>
24 #include <comphelper/multiinterfacecontainer4.hxx>
25 #include <rtl/ustring.hxx>
26 #include <o3tl/enumarray.hxx>
29 #include <unordered_map>
31 namespace com::sun::star::beans
{ class XPropertyChangeListener
; }
32 namespace com::sun::star::uno
{ class Any
; }
33 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
34 namespace osl
{ class Mutex
; }
47 enum class ShapePropertyProviderId
49 // generic (UNO) shape properties
52 // text doc shape properties
57 //= PropertyValueProvider
59 /** Default provider for a property value
61 This default implementation queries the object which it is constructed with for the XPropertySet interface,
62 and calls the getPropertyValue method.
64 class SVXCORE_DLLPUBLIC PropertyValueProvider
67 PropertyValueProvider( ::cppu::OWeakObject
& _rContext
, OUString _aPropertyName
)
68 :m_rContext( _rContext
)
69 ,m_sPropertyName( std::move( _aPropertyName
) )
72 virtual ~PropertyValueProvider();
74 /** returns the name of the property which this provider is responsible for
76 const OUString
& getPropertyName() const;
77 /** returns the current value of the property which the provider is responsible for
79 virtual void getCurrentValue( css::uno::Any
& _out_rValue
) const;
82 ::cppu::OWeakObject
& getContext() const { return m_rContext
; }
83 PropertyValueProvider(const PropertyValueProvider
&) = delete;
84 PropertyValueProvider
& operator=(const PropertyValueProvider
&) = delete;
87 ::cppu::OWeakObject
& m_rContext
;
88 const OUString m_sPropertyName
;
92 /** helper class for notifying XPropertyChangeListeners
94 The class is intended to be held as member of the class which does the property change broadcasting.
96 class SVXCORE_DLLPUBLIC PropertyChangeNotifier
99 /** constructs a notifier instance
102 the owner instance of the notifier. Will be used as css.lang.EventObject.Source when
105 PropertyChangeNotifier( ::cppu::OWeakObject
& _rOwner
);
106 ~PropertyChangeNotifier();
108 // listener maintenance
109 void addPropertyChangeListener( std::unique_lock
<std::mutex
>& rGuard
, const OUString
& _rPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& _rxListener
);
110 void removePropertyChangeListener( std::unique_lock
<std::mutex
>& rGuard
, const OUString
& _rPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& _rxListener
);
112 /** registers an PropertyValueProvider
114 void registerProvider( const ShapePropertyProviderId _eProperty
, std::unique_ptr
<PropertyValueProvider
> _rProvider
);
116 /** notifies changes in the given property to all registered listeners
118 If no property value provider for the given property ID is registered, this is worth an assertion in a
119 non-product build, and otherwise ignored.
121 void notifyPropertyChange( std::unique_lock
<std::mutex
>& rGuard
, const ShapePropertyProviderId _eProperty
) const;
123 /** is called to dispose the instance
125 void disposing(std::unique_lock
<std::mutex
>& rGuard
);
128 PropertyChangeNotifier(const PropertyChangeNotifier
&) = delete;
129 PropertyChangeNotifier
& operator=(const PropertyChangeNotifier
&) = delete;
131 ::cppu::OWeakObject
& m_rContext
;
132 o3tl::enumarray
<ShapePropertyProviderId
, std::unique_ptr
<PropertyValueProvider
>> m_aProviders
;
133 comphelper::OMultiTypeInterfaceContainerHelperVar4
<OUString
, css::beans::XPropertyChangeListener
> m_aPropertyChangeListeners
;
140 #endif // INCLUDED_SVX_SHAPEPROPERTYNOTIFIER_HXX
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */