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