1*2d785d7eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2d785d7eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2d785d7eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2d785d7eSAndrew Rist  * distributed with this work for additional information
6*2d785d7eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2d785d7eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2d785d7eSAndrew Rist  * "License"); you may not use this file except in compliance
9*2d785d7eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2d785d7eSAndrew Rist  *
11*2d785d7eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2d785d7eSAndrew Rist  *
13*2d785d7eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2d785d7eSAndrew Rist  * software distributed under the License is distributed on an
15*2d785d7eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2d785d7eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2d785d7eSAndrew Rist  * specific language governing permissions and limitations
18*2d785d7eSAndrew Rist  * under the License.
19*2d785d7eSAndrew Rist  *
20*2d785d7eSAndrew Rist  *************************************************************/
21*2d785d7eSAndrew Rist 
22*2d785d7eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef FORMS_PROPERTYBAGHELPER_HXX
25cdf0e10cSrcweir #define FORMS_PROPERTYBAGHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /** === begin UNO includes === **/
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
29cdf0e10cSrcweir /** === end UNO includes === **/
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <comphelper/propertybag.hxx>
32cdf0e10cSrcweir #include <comphelper/propagg.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <boost/noncopyable.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //........................................................................
37cdf0e10cSrcweir namespace frm
38cdf0e10cSrcweir {
39cdf0e10cSrcweir //........................................................................
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 	//====================================================================
42cdf0e10cSrcweir 	//= class IPropertyBagHelperContext
43cdf0e10cSrcweir 	//====================================================================
44cdf0e10cSrcweir     class SAL_NO_VTABLE IPropertyBagHelperContext
45cdf0e10cSrcweir     {
46cdf0e10cSrcweir     public:
47cdf0e10cSrcweir         virtual ::osl::Mutex&   getMutex() = 0;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir         virtual void            describeFixedAndAggregateProperties(
50cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rFixedProperties,
51cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rAggregateProperties
52cdf0e10cSrcweir         ) const = 0;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet >
55cdf0e10cSrcweir                                 getPropertiesInterface() = 0;
56cdf0e10cSrcweir     };
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	//====================================================================
59cdf0e10cSrcweir 	//= class PropertyBagHelper
60cdf0e10cSrcweir 	//====================================================================
61cdf0e10cSrcweir     class PropertyBagHelper : public ::boost::noncopyable
62cdf0e10cSrcweir 	{
63cdf0e10cSrcweir     private:
64cdf0e10cSrcweir         IPropertyBagHelperContext&                      m_rContext;
65cdf0e10cSrcweir         ::comphelper::OPropertyArrayAggregationHelper*  m_pPropertyArrayHelper;
66cdf0e10cSrcweir         ::comphelper::PropertyBag                       m_aDynamicProperties;
67cdf0e10cSrcweir         bool                                            m_bDisposed;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     public:
70cdf0e10cSrcweir         PropertyBagHelper( IPropertyBagHelperContext& _rContext );
71cdf0e10cSrcweir         ~PropertyBagHelper();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         // XComponent equivalent
74cdf0e10cSrcweir         void    dispose();
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         // OPropertySetHelper equivalent
77cdf0e10cSrcweir         inline ::comphelper::OPropertyArrayAggregationHelper& getInfoHelper() const;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         // XPropertyContainer equivalent
80cdf0e10cSrcweir         void addProperty( const ::rtl::OUString& _rName, ::sal_Int16 _nAttributes, const ::com::sun::star::uno::Any& _rInitialValue );
81cdf0e10cSrcweir         void removeProperty( const ::rtl::OUString& _rName );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // XPropertyAccess equivalent
84cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues();
85cdf0e10cSrcweir         void setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         // forwards to m_aDynamicProperties
88cdf0e10cSrcweir         inline void getDynamicFastPropertyValue( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const;
89cdf0e10cSrcweir 	    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;
90cdf0e10cSrcweir         inline void setDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue );
91cdf0e10cSrcweir         inline void getDynamicPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const;
92cdf0e10cSrcweir         inline bool hasDynamicPropertyByName( const ::rtl::OUString& _rName ) const;
93cdf0e10cSrcweir         inline bool hasDynamicPropertyByHandle( sal_Int32 _nHandle ) const;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     private:
96cdf0e10cSrcweir         void    impl_nts_checkDisposed_throw() const;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         /** invalidates our property set info, so subsequent calls to impl_ts_getArrayHelper and thus
99cdf0e10cSrcweir             getInfoHelper will return a newly created instance
100cdf0e10cSrcweir         */
101cdf0e10cSrcweir         void    impl_nts_invalidatePropertySetInfo();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         /** returns the IPropertyArrayHelper instance used by |this|
104cdf0e10cSrcweir         */
105cdf0e10cSrcweir         ::comphelper::OPropertyArrayAggregationHelper& impl_ts_getArrayHelper() const;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         /** finds a free property handle
108cdf0e10cSrcweir             @param _rPropertyName
109cdf0e10cSrcweir                 the name of the property to find a handle for. If possible, the handle as determined by
110cdf0e10cSrcweir                 our ConcreteInfoService instance will be used
111cdf0e10cSrcweir         */
112cdf0e10cSrcweir         sal_Int32   impl_findFreeHandle( const ::rtl::OUString& _rPropertyName );
113cdf0e10cSrcweir 	};
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	//--------------------------------------------------------------------
getInfoHelper() const116cdf0e10cSrcweir     inline ::comphelper::OPropertyArrayAggregationHelper& PropertyBagHelper::getInfoHelper() const
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         return impl_ts_getArrayHelper();
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	//--------------------------------------------------------------------
getDynamicFastPropertyValue(sal_Int32 _nHandle,::com::sun::star::uno::Any & _out_rValue) const122cdf0e10cSrcweir     inline void PropertyBagHelper::getDynamicFastPropertyValue( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         m_aDynamicProperties.getFastPropertyValue( _nHandle, _out_rValue );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	//--------------------------------------------------------------------
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) const128cdf0e10cSrcweir     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
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         return m_aDynamicProperties.convertFastPropertyValue( _nHandle, _rNewValue, _out_rConvertedValue, _out_rCurrentValue );
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	//--------------------------------------------------------------------
setDynamicFastPropertyValue(sal_Int32 _nHandle,const::com::sun::star::uno::Any & _rValue)134cdf0e10cSrcweir     inline void PropertyBagHelper::setDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         m_aDynamicProperties.setFastPropertyValue( _nHandle, _rValue );
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	//--------------------------------------------------------------------
getDynamicPropertyDefaultByHandle(sal_Int32 _nHandle,::com::sun::star::uno::Any & _out_rValue) const140cdf0e10cSrcweir     inline void PropertyBagHelper::getDynamicPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         m_aDynamicProperties.getPropertyDefaultByHandle( _nHandle, _out_rValue );
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	//--------------------------------------------------------------------
hasDynamicPropertyByName(const::rtl::OUString & _rName) const146cdf0e10cSrcweir     inline bool PropertyBagHelper::hasDynamicPropertyByName( const ::rtl::OUString& _rName ) const
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         return m_aDynamicProperties.hasPropertyByName( _rName );
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	//--------------------------------------------------------------------
hasDynamicPropertyByHandle(sal_Int32 _nHandle) const152cdf0e10cSrcweir     inline bool PropertyBagHelper::hasDynamicPropertyByHandle( sal_Int32 _nHandle ) const
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         return m_aDynamicProperties.hasPropertyByHandle( _nHandle );
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir //........................................................................
158cdf0e10cSrcweir } // namespace frm
159cdf0e10cSrcweir //........................................................................
160cdf0e10cSrcweir 
161cdf0e10cSrcweir #endif // FORMS_PROPERTYBAGHELPER_HXX
162cdf0e10cSrcweir 
163