Branch data Line data Source code
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 : : #ifndef SVX_PROPERTYCHANGENOTIFIER_HXX
21 : : #define SVX_PROPERTYCHANGENOTIFIER_HXX
22 : :
23 : : #include "svx/svxdllapi.h"
24 : : #include "svx/shapeproperty.hxx"
25 : :
26 : : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
27 : : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
28 : :
29 : : #include <boost/noncopyable.hpp>
30 : : #include <boost/shared_ptr.hpp>
31 : : #include <memory>
32 : :
33 : : namespace cppu
34 : : {
35 : : class OWeakObject;
36 : : }
37 : :
38 : : //........................................................................
39 : : namespace svx
40 : : {
41 : : //........................................................................
42 : :
43 : : //====================================================================
44 : : //= IPropertyValueProvider
45 : : //====================================================================
46 : : /** a provider for a property value
47 : : */
48 : 1153 : class SVX_DLLPUBLIC IPropertyValueProvider
49 : : {
50 : : public:
51 : : /** returns the name of the property which this provider is responsible for
52 : : */
53 : : virtual ::rtl::OUString getPropertyName() const = 0;
54 : :
55 : : /** returns the current value of the property which the provider is responsible for
56 : : */
57 : : virtual void getCurrentValue( ::com::sun::star::uno::Any& _out_rValue ) const = 0;
58 : :
59 : : virtual ~IPropertyValueProvider();
60 : : };
61 : : typedef ::boost::shared_ptr< IPropertyValueProvider > PPropertyValueProvider;
62 : :
63 : : //====================================================================
64 : : //= PropertyValueProvider
65 : : //====================================================================
66 : : /** default implementation of a IPropertyValueProvider
67 : :
68 : : This default implementation queries the object which it is constructed with for the XPropertySet interface,
69 : : and calls the getPropertyValue method.
70 : : */
71 [ # # ]: 0 : class SVX_DLLPUBLIC PropertyValueProvider :public IPropertyValueProvider
72 : : ,public ::boost::noncopyable
73 : : {
74 : : public:
75 : 1153 : PropertyValueProvider( ::cppu::OWeakObject& _rContext, const sal_Char* _pAsciiPropertyName )
76 : : :m_rContext( _rContext )
77 : 1153 : ,m_sPropertyName( ::rtl::OUString::createFromAscii( _pAsciiPropertyName ) )
78 : : {
79 : 1153 : }
80 : :
81 : : virtual ::rtl::OUString getPropertyName() const;
82 : : virtual void getCurrentValue( ::com::sun::star::uno::Any& _out_rValue ) const;
83 : :
84 : : protected:
85 : : ::cppu::OWeakObject& getContext() const { return m_rContext; }
86 : : private:
87 : : ::cppu::OWeakObject& m_rContext;
88 : : const ::rtl::OUString m_sPropertyName;
89 : : };
90 : :
91 : : //====================================================================
92 : : //= PropertyChangeNotifier
93 : : //====================================================================
94 : : struct PropertyChangeNotifier_Data;
95 : :
96 : : /** helper class for notifying XPropertyChangeListeners
97 : :
98 : : The class is intended to be held as member of the class which does the property change broadcasting.
99 : : */
100 : : class SVX_DLLPUBLIC PropertyChangeNotifier : public ::boost::noncopyable
101 : : {
102 : : public:
103 : : /** constructs a notifier instance
104 : :
105 : : @param _rOwner
106 : : the owner instance of the notifier. Will be used as css.lang.EventObject.Source when
107 : : notifying events.
108 : : */
109 : : PropertyChangeNotifier( ::cppu::OWeakObject& _rOwner, ::osl::Mutex& _rMutex );
110 : : ~PropertyChangeNotifier();
111 : :
112 : : // listener maintanance
113 : : void addPropertyChangeListener( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener );
114 : : void removePropertyChangeListener( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener );
115 : :
116 : : /** registers a IPropertyValueProvider
117 : : */
118 : : void registerProvider( const ShapeProperty _eProperty, const PPropertyValueProvider _pProvider );
119 : :
120 : : /** notifies changes in the given property to all registered listeners
121 : :
122 : : If no property value provider for the given property ID is registered, this is worth an assertion in a
123 : : non-product build, and otherwise ignored.
124 : : */
125 : : void notifyPropertyChange( const ShapeProperty _eProperty ) const;
126 : :
127 : : /** is called to dispose the instance
128 : : */
129 : : void disposing();
130 : :
131 : : private:
132 : : ::std::auto_ptr< PropertyChangeNotifier_Data > m_pData;
133 : : };
134 : :
135 : : //........................................................................
136 : : } // namespace svx
137 : : //........................................................................
138 : :
139 : : #endif // SVX_PROPERTYCHANGENOTIFIER_HXX
140 : :
141 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|