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 FORMS_PROPERTYBAGHELPER_HXX
25 #define FORMS_PROPERTYBAGHELPER_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 /** === end UNO includes === **/
30 
31 #include <comphelper/propertybag.hxx>
32 #include <comphelper/propagg.hxx>
33 
34 #include <boost/noncopyable.hpp>
35 
36 //........................................................................
37 namespace frm
38 {
39 //........................................................................
40 
41 	//====================================================================
42 	//= class IPropertyBagHelperContext
43 	//====================================================================
44     class SAL_NO_VTABLE IPropertyBagHelperContext
45     {
46     public:
47         virtual ::osl::Mutex&   getMutex() = 0;
48 
49         virtual void            describeFixedAndAggregateProperties(
50             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rFixedProperties,
51             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rAggregateProperties
52         ) const = 0;
53 
54         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet >
55                                 getPropertiesInterface() = 0;
56     };
57 
58 	//====================================================================
59 	//= class PropertyBagHelper
60 	//====================================================================
61     class PropertyBagHelper : public ::boost::noncopyable
62 	{
63     private:
64         IPropertyBagHelperContext&                      m_rContext;
65         ::comphelper::OPropertyArrayAggregationHelper*  m_pPropertyArrayHelper;
66         ::comphelper::PropertyBag                       m_aDynamicProperties;
67         bool                                            m_bDisposed;
68 
69     public:
70         PropertyBagHelper( IPropertyBagHelperContext& _rContext );
71         ~PropertyBagHelper();
72 
73         // XComponent equivalent
74         void    dispose();
75 
76         // OPropertySetHelper equivalent
77         inline ::comphelper::OPropertyArrayAggregationHelper& getInfoHelper() const;
78 
79         // XPropertyContainer equivalent
80         void addProperty( const ::rtl::OUString& _rName, ::sal_Int16 _nAttributes, const ::com::sun::star::uno::Any& _rInitialValue );
81         void removeProperty( const ::rtl::OUString& _rName );
82 
83         // XPropertyAccess equivalent
84         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues();
85         void setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps );
86 
87         // forwards to m_aDynamicProperties
88         inline void getDynamicFastPropertyValue( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const;
89 	    inline bool convertDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::com::sun::star::uno::Any& _out_rConvertedValue, ::com::sun::star::uno::Any& _out_rCurrentValue ) const;
90         inline void setDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue );
91         inline void getDynamicPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const;
92         inline bool hasDynamicPropertyByName( const ::rtl::OUString& _rName ) const;
93         inline bool hasDynamicPropertyByHandle( sal_Int32 _nHandle ) const;
94 
95     private:
96         void    impl_nts_checkDisposed_throw() const;
97 
98         /** invalidates our property set info, so subsequent calls to impl_ts_getArrayHelper and thus
99             getInfoHelper will return a newly created instance
100         */
101         void    impl_nts_invalidatePropertySetInfo();
102 
103         /** returns the IPropertyArrayHelper instance used by |this|
104         */
105         ::comphelper::OPropertyArrayAggregationHelper& impl_ts_getArrayHelper() const;
106 
107         /** finds a free property handle
108             @param _rPropertyName
109                 the name of the property to find a handle for. If possible, the handle as determined by
110                 our ConcreteInfoService instance will be used
111         */
112         sal_Int32   impl_findFreeHandle( const ::rtl::OUString& _rPropertyName );
113 	};
114 
115 	//--------------------------------------------------------------------
getInfoHelper() const116     inline ::comphelper::OPropertyArrayAggregationHelper& PropertyBagHelper::getInfoHelper() const
117     {
118         return impl_ts_getArrayHelper();
119     }
120 
121 	//--------------------------------------------------------------------
getDynamicFastPropertyValue(sal_Int32 _nHandle,::com::sun::star::uno::Any & _out_rValue) const122     inline void PropertyBagHelper::getDynamicFastPropertyValue( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const
123     {
124         m_aDynamicProperties.getFastPropertyValue( _nHandle, _out_rValue );
125     }
126 
127 	//--------------------------------------------------------------------
convertDynamicFastPropertyValue(sal_Int32 _nHandle,const::com::sun::star::uno::Any & _rNewValue,::com::sun::star::uno::Any & _out_rConvertedValue,::com::sun::star::uno::Any & _out_rCurrentValue) const128     inline bool PropertyBagHelper::convertDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::com::sun::star::uno::Any& _out_rConvertedValue, ::com::sun::star::uno::Any& _out_rCurrentValue ) const
129     {
130         return m_aDynamicProperties.convertFastPropertyValue( _nHandle, _rNewValue, _out_rConvertedValue, _out_rCurrentValue );
131     }
132 
133 	//--------------------------------------------------------------------
setDynamicFastPropertyValue(sal_Int32 _nHandle,const::com::sun::star::uno::Any & _rValue)134     inline void PropertyBagHelper::setDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
135     {
136         m_aDynamicProperties.setFastPropertyValue( _nHandle, _rValue );
137     }
138 
139 	//--------------------------------------------------------------------
getDynamicPropertyDefaultByHandle(sal_Int32 _nHandle,::com::sun::star::uno::Any & _out_rValue) const140     inline void PropertyBagHelper::getDynamicPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const
141     {
142         m_aDynamicProperties.getPropertyDefaultByHandle( _nHandle, _out_rValue );
143     }
144 
145 	//--------------------------------------------------------------------
hasDynamicPropertyByName(const::rtl::OUString & _rName) const146     inline bool PropertyBagHelper::hasDynamicPropertyByName( const ::rtl::OUString& _rName ) const
147     {
148         return m_aDynamicProperties.hasPropertyByName( _rName );
149     }
150 
151 	//--------------------------------------------------------------------
hasDynamicPropertyByHandle(sal_Int32 _nHandle) const152     inline bool PropertyBagHelper::hasDynamicPropertyByHandle( sal_Int32 _nHandle ) const
153     {
154         return m_aDynamicProperties.hasPropertyByHandle( _nHandle );
155     }
156 
157 //........................................................................
158 } // namespace frm
159 //........................................................................
160 
161 #endif // FORMS_PROPERTYBAGHELPER_HXX
162 
163