1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef FORMS_PROPERTYBAGHELPER_HXX 29 #define FORMS_PROPERTYBAGHELPER_HXX 30 31 /** === begin UNO includes === **/ 32 #include <com/sun/star/beans/PropertyValue.hpp> 33 /** === end UNO includes === **/ 34 35 #include <comphelper/propertybag.hxx> 36 #include <comphelper/propagg.hxx> 37 38 #include <boost/noncopyable.hpp> 39 40 //........................................................................ 41 namespace frm 42 { 43 //........................................................................ 44 45 //==================================================================== 46 //= class IPropertyBagHelperContext 47 //==================================================================== 48 class SAL_NO_VTABLE IPropertyBagHelperContext 49 { 50 public: 51 virtual ::osl::Mutex& getMutex() = 0; 52 53 virtual void describeFixedAndAggregateProperties( 54 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rFixedProperties, 55 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rAggregateProperties 56 ) const = 0; 57 58 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > 59 getPropertiesInterface() = 0; 60 }; 61 62 //==================================================================== 63 //= class PropertyBagHelper 64 //==================================================================== 65 class PropertyBagHelper : public ::boost::noncopyable 66 { 67 private: 68 IPropertyBagHelperContext& m_rContext; 69 ::comphelper::OPropertyArrayAggregationHelper* m_pPropertyArrayHelper; 70 ::comphelper::PropertyBag m_aDynamicProperties; 71 bool m_bDisposed; 72 73 public: 74 PropertyBagHelper( IPropertyBagHelperContext& _rContext ); 75 ~PropertyBagHelper(); 76 77 // XComponent equivalent 78 void dispose(); 79 80 // OPropertySetHelper equivalent 81 inline ::comphelper::OPropertyArrayAggregationHelper& getInfoHelper() const; 82 83 // XPropertyContainer equivalent 84 void addProperty( const ::rtl::OUString& _rName, ::sal_Int16 _nAttributes, const ::com::sun::star::uno::Any& _rInitialValue ); 85 void removeProperty( const ::rtl::OUString& _rName ); 86 87 // XPropertyAccess equivalent 88 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues(); 89 void setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps ); 90 91 // forwards to m_aDynamicProperties 92 inline void getDynamicFastPropertyValue( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const; 93 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; 94 inline void setDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ); 95 inline void getDynamicPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const; 96 inline bool hasDynamicPropertyByName( const ::rtl::OUString& _rName ) const; 97 inline bool hasDynamicPropertyByHandle( sal_Int32 _nHandle ) const; 98 99 private: 100 void impl_nts_checkDisposed_throw() const; 101 102 /** invalidates our property set info, so subsequent calls to impl_ts_getArrayHelper and thus 103 getInfoHelper will return a newly created instance 104 */ 105 void impl_nts_invalidatePropertySetInfo(); 106 107 /** returns the IPropertyArrayHelper instance used by |this| 108 */ 109 ::comphelper::OPropertyArrayAggregationHelper& impl_ts_getArrayHelper() const; 110 111 /** finds a free property handle 112 @param _rPropertyName 113 the name of the property to find a handle for. If possible, the handle as determined by 114 our ConcreteInfoService instance will be used 115 */ 116 sal_Int32 impl_findFreeHandle( const ::rtl::OUString& _rPropertyName ); 117 }; 118 119 //-------------------------------------------------------------------- 120 inline ::comphelper::OPropertyArrayAggregationHelper& PropertyBagHelper::getInfoHelper() const 121 { 122 return impl_ts_getArrayHelper(); 123 } 124 125 //-------------------------------------------------------------------- 126 inline void PropertyBagHelper::getDynamicFastPropertyValue( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const 127 { 128 m_aDynamicProperties.getFastPropertyValue( _nHandle, _out_rValue ); 129 } 130 131 //-------------------------------------------------------------------- 132 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 133 { 134 return m_aDynamicProperties.convertFastPropertyValue( _nHandle, _rNewValue, _out_rConvertedValue, _out_rCurrentValue ); 135 } 136 137 //-------------------------------------------------------------------- 138 inline void PropertyBagHelper::setDynamicFastPropertyValue( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) 139 { 140 m_aDynamicProperties.setFastPropertyValue( _nHandle, _rValue ); 141 } 142 143 //-------------------------------------------------------------------- 144 inline void PropertyBagHelper::getDynamicPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _out_rValue ) const 145 { 146 m_aDynamicProperties.getPropertyDefaultByHandle( _nHandle, _out_rValue ); 147 } 148 149 //-------------------------------------------------------------------- 150 inline bool PropertyBagHelper::hasDynamicPropertyByName( const ::rtl::OUString& _rName ) const 151 { 152 return m_aDynamicProperties.hasPropertyByName( _rName ); 153 } 154 155 //-------------------------------------------------------------------- 156 inline bool PropertyBagHelper::hasDynamicPropertyByHandle( sal_Int32 _nHandle ) const 157 { 158 return m_aDynamicProperties.hasPropertyByHandle( _nHandle ); 159 } 160 161 //........................................................................ 162 } // namespace frm 163 //........................................................................ 164 165 #endif // FORMS_PROPERTYBAGHELPER_HXX 166 167