xref: /trunk/main/comphelper/inc/comphelper/MasterPropertySet.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 _COMPHELPER_MASTERPROPERTYSETHELPER_HXX_
25 #define _COMPHELPER_MASTERPROPERTYSETHELPER_HXX_
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/beans/XPropertyState.hpp>
28 #include <com/sun/star/beans/XMultiPropertySet.hpp>
29 #include <comphelper/PropertyInfoHash.hxx>
30 #include "comphelper/comphelperdllapi.h"
31 #include <map>
32 namespace vos
33 {
34     class IMutex;
35 }
36 namespace comphelper
37 {
38     class MasterPropertySetInfo;
39     class ChainablePropertySet;
40     struct SlaveData
41     {
42         ChainablePropertySet * mpSlave;
43         ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > mxSlave;
44         sal_Bool mbInit;
45         SlaveData ( ChainablePropertySet *pSlave);
IsInitcomphelper::SlaveData46         inline sal_Bool IsInit () { return mbInit;}
SetInitcomphelper::SlaveData47         inline void SetInit ( sal_Bool bInit) { mbInit = bInit; }
48     };
49 }
50 typedef std::map < sal_uInt8, comphelper::SlaveData* > SlaveMap;
51 
52 /*
53  * A MasterPropertySet implements all of the features of a ChainablePropertySet
54  * (it is not inherited from ChainablePropertySet to prevent MasterPropertySets
55  * being chained to each other), but also allows properties implemented in
56  * other ChainablePropertySets to be included as 'native' properties in a
57  * given MasterPropertySet implementation. These are registered using the
58  * 'registerSlave' method, and require that the implementation of the
59  * ChainablePropertySet and the implementation of the ChainablePropertySetInfo
60  * both declare the implementation of the MasterPropertySet as a friend.
61  */
62 namespace comphelper
63 {
64     class COMPHELPER_DLLPUBLIC MasterPropertySet : public ::com::sun::star::beans::XPropertySet,
65                               public ::com::sun::star::beans::XPropertyState,
66                               public ::com::sun::star::beans::XMultiPropertySet
67     {
68     protected:
69         MasterPropertySetInfo *mpInfo;
70         vos::IMutex *mpMutex;
71         sal_uInt8 mnLastId;
72         SlaveMap maSlaveMap;
73         ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySetInfo > mxInfo;
74         void lockMutex();
75         void unlockMutex();
76 
77         virtual void _preSetValues () = 0;
78         virtual void _setSingleValue( const comphelper::PropertyInfo & rInfo, const ::com::sun::star::uno::Any &rValue ) = 0;
79         virtual void _postSetValues () = 0;
80 
81         virtual void _preGetValues () = 0;
82         virtual void _getSingleValue( const comphelper::PropertyInfo & rInfo, ::com::sun::star::uno::Any & rValue ) = 0;
83         virtual void _postGetValues () = 0;
84 
85         virtual void _preGetPropertyState ();
86         virtual void _getPropertyState( const comphelper::PropertyInfo& rInfo, ::com::sun::star::beans::PropertyState& rState );
87         virtual void _postGetPropertyState ();
88 
89         virtual void _setPropertyToDefault( const comphelper::PropertyInfo& rEntry );
90         virtual ::com::sun::star::uno::Any _getPropertyDefault( const comphelper::PropertyInfo& rEntry );
91 
92     public:
93         MasterPropertySet( comphelper::MasterPropertySetInfo* pInfo, ::vos::IMutex *pMutex = NULL )
94             throw();
95         virtual ~MasterPropertySet()
96             throw();
97         void registerSlave ( ChainablePropertySet *pNewSet )
98             throw();
99 
100         // XPropertySet
101         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  );
102         virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue );
103         virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName );
104         virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener );
105         virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener );
106         virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener );
107         virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener );
108 
109         // XMultiPropertySet
110         virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues );
111         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames );
112         virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener );
113         virtual void SAL_CALL removePropertiesChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener );
114         virtual void SAL_CALL firePropertiesChangeEvent( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener );
115 
116         // XPropertyState
117         virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& PropertyName );
118         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > SAL_CALL getPropertyStates( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyName );
119         virtual void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName );
120         virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName );
121     };
122 }
123 #endif
124