1*3334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3334a7e6SAndrew Rist  * distributed with this work for additional information
6*3334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
9*3334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3334a7e6SAndrew Rist  *
11*3334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3334a7e6SAndrew Rist  *
13*3334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3334a7e6SAndrew Rist  * software distributed under the License is distributed on an
15*3334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3334a7e6SAndrew Rist  * specific language governing permissions and limitations
18*3334a7e6SAndrew Rist  * under the License.
19*3334a7e6SAndrew Rist  *
20*3334a7e6SAndrew Rist  *************************************************************/
21*3334a7e6SAndrew Rist 
22*3334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SVX_PROPERTYCHANGENOTIFIER_HXX
25cdf0e10cSrcweir #define SVX_PROPERTYCHANGENOTIFIER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "svx/svxdllapi.h"
28cdf0e10cSrcweir #include "svx/shapeproperty.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /** === begin UNO includes === **/
31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
33cdf0e10cSrcweir /** === end UNO includes === **/
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <boost/noncopyable.hpp>
36cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
37cdf0e10cSrcweir #include <memory>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace cppu
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     class OWeakObject;
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //........................................................................
45cdf0e10cSrcweir namespace svx
46cdf0e10cSrcweir {
47cdf0e10cSrcweir //........................................................................
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	//====================================================================
50cdf0e10cSrcweir 	//= IPropertyValueProvider
51cdf0e10cSrcweir 	//====================================================================
52cdf0e10cSrcweir     /** a provider for a property value
53cdf0e10cSrcweir     */
54cdf0e10cSrcweir     class SVX_DLLPUBLIC IPropertyValueProvider
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir     public:
57cdf0e10cSrcweir         /** returns the name of the property which this provider is responsible for
58cdf0e10cSrcweir         */
59cdf0e10cSrcweir         virtual ::rtl::OUString getPropertyName() const = 0;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         /** returns the current value of the property which the provider is responsible for
62cdf0e10cSrcweir         */
63cdf0e10cSrcweir         virtual void getCurrentValue( ::com::sun::star::uno::Any& _out_rValue ) const = 0;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         virtual ~IPropertyValueProvider();
66cdf0e10cSrcweir     };
67cdf0e10cSrcweir     typedef ::boost::shared_ptr< IPropertyValueProvider >  PPropertyValueProvider;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	//====================================================================
70cdf0e10cSrcweir 	//= PropertyValueProvider
71cdf0e10cSrcweir 	//====================================================================
72cdf0e10cSrcweir     /** default implementation of a IPropertyValueProvider
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         This default implementation queries the object which it is constructed with for the XPropertySet interface,
75cdf0e10cSrcweir         and calls the getPropertyValue method.
76cdf0e10cSrcweir     */
77cdf0e10cSrcweir     class SVX_DLLPUBLIC PropertyValueProvider   :public IPropertyValueProvider
78cdf0e10cSrcweir                                                 ,public ::boost::noncopyable
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir     public:
PropertyValueProvider(::cppu::OWeakObject & _rContext,const sal_Char * _pAsciiPropertyName)81cdf0e10cSrcweir         PropertyValueProvider( ::cppu::OWeakObject& _rContext, const sal_Char* _pAsciiPropertyName )
82cdf0e10cSrcweir             :m_rContext( _rContext )
83cdf0e10cSrcweir             ,m_sPropertyName( ::rtl::OUString::createFromAscii( _pAsciiPropertyName ) )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         virtual ::rtl::OUString getPropertyName() const;
88cdf0e10cSrcweir         virtual void getCurrentValue( ::com::sun::star::uno::Any& _out_rValue ) const;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     protected:
getContext() const91cdf0e10cSrcweir         ::cppu::OWeakObject&    getContext() const { return m_rContext; }
92cdf0e10cSrcweir     private:
93cdf0e10cSrcweir         ::cppu::OWeakObject&    m_rContext;
94cdf0e10cSrcweir         const ::rtl::OUString   m_sPropertyName;
95cdf0e10cSrcweir     };
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	//====================================================================
98cdf0e10cSrcweir 	//= PropertyChangeNotifier
99cdf0e10cSrcweir 	//====================================================================
100cdf0e10cSrcweir     struct PropertyChangeNotifier_Data;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /** helper class for notifying XPropertyChangeListeners
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         The class is intended to be held as member of the class which does the property change broadcasting.
105cdf0e10cSrcweir     */
106cdf0e10cSrcweir     class SVX_DLLPUBLIC PropertyChangeNotifier : public ::boost::noncopyable
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir     public:
109cdf0e10cSrcweir         /** constructs a notifier instance
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             @param _rOwner
112cdf0e10cSrcweir                 the owner instance of the notifier. Will be used as css.lang.EventObject.Source when
113cdf0e10cSrcweir                 notifying events.
114cdf0e10cSrcweir         */
115cdf0e10cSrcweir         PropertyChangeNotifier( ::cppu::OWeakObject& _rOwner, ::osl::Mutex& _rMutex );
116cdf0e10cSrcweir         ~PropertyChangeNotifier();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         // listener maintanance
119cdf0e10cSrcweir         void addPropertyChangeListener( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener );
120cdf0e10cSrcweir         void removePropertyChangeListener( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         /** registers a IPropertyValueProvider
123cdf0e10cSrcweir         */
124cdf0e10cSrcweir         void    registerProvider( const ShapeProperty _eProperty, const PPropertyValueProvider _pProvider );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         /** notifies changes in the given property to all registered listeners
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             If no property value provider for the given property ID is registered, this is worth an assertion in a
129cdf0e10cSrcweir             non-product build, and otherwise ignored.
130cdf0e10cSrcweir         */
131cdf0e10cSrcweir         void    notifyPropertyChange( const ShapeProperty _eProperty ) const;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         /** is called to dispose the instance
134cdf0e10cSrcweir         */
135cdf0e10cSrcweir         void    disposing();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     private:
138cdf0e10cSrcweir         ::std::auto_ptr< PropertyChangeNotifier_Data >  m_pData;
139cdf0e10cSrcweir 	};
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //........................................................................
142cdf0e10cSrcweir } // namespace svx
143cdf0e10cSrcweir //........................................................................
144cdf0e10cSrcweir 
145cdf0e10cSrcweir #endif // SVX_PROPERTYCHANGENOTIFIER_HXX
146