1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
21 #define INCLUDED_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/util/XModifiable.hpp>
27 #include <com/sun/star/beans/XPropertyBag.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/container/XSet.hpp>
31 #include <boost/noncopyable.hpp>
32 #include <cppuhelper/implbase5.hxx>
33 #include <comphelper/propstate.hxx>
34 #include <comphelper/broadcasthelper.hxx>
35 #include <comphelper/propertybag.hxx>
36 #include <comphelper/uno3.hxx>
47 struct UnoTypeLess
: public ::std::unary_function
< ::com::sun::star::uno::Type
, bool >
49 inline bool operator()( const ::com::sun::star::uno::Type
& _rLHS
, const ::com::sun::star::uno::Type
& _rRHS
) const
51 return rtl_ustr_compare(
52 _rLHS
.getTypeLibType()->pTypeName
->buffer
,
53 _rRHS
.getTypeLibType()->pTypeName
->buffer
58 typedef ::std::map
< sal_Int32
, ::com::sun::star::uno::Any
> MapInt2Any
;
59 typedef ::std::set
< ::com::sun::star::uno::Type
, UnoTypeLess
> TypeBag
;
61 typedef ::cppu::WeakAggImplHelper5
< ::com::sun::star::beans::XPropertyBag
62 , ::com::sun::star::util::XModifiable
63 , ::com::sun::star::lang::XServiceInfo
64 , ::com::sun::star::lang::XInitialization
65 , ::com::sun::star::container::XSet
67 typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase
;
69 class OPropertyBag
:public ::comphelper::OMutexAndBroadcastHelper
// must be before OPropertyBag_PBase
70 ,public OPropertyBag_PBase
71 ,public OPropertyBag_Base
72 ,public ::cppu::IEventNotificationHook
73 ,private boost::noncopyable
76 /// our IPropertyArrayHelper implementation
77 ::std::unique_ptr
< ::cppu::OPropertyArrayHelper
>
79 ::comphelper::PropertyBag
81 /// set of allowed property types
82 TypeBag m_aAllowedTypes
;
83 /// should we automatically add properties which are tried to set, if they don't exist previously?
84 bool m_bAutoAddProperties
;
87 ::cppu::OInterfaceContainerHelper m_NotifyListeners
;
92 // XServiceInfo - static versions
93 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_static() throw( ::com::sun::star::uno::RuntimeException
);
94 static OUString
getImplementationName_static() throw( ::com::sun::star::uno::RuntimeException
);
95 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
96 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
100 virtual ~OPropertyBag();
102 DECLARE_XTYPEPROVIDER()
104 /** === begin UNO interface implementations == **/
106 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 virtual OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
110 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 virtual sal_Bool SAL_CALL
isModified( )
115 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 virtual void SAL_CALL
setModified( sal_Bool bModified
)
117 throw (::com::sun::star::beans::PropertyVetoException
,
118 ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 // XModifyBroadcaster
121 virtual void SAL_CALL
addModifyListener(
122 const ::com::sun::star::uno::Reference
<
123 ::com::sun::star::util::XModifyListener
> & xListener
)
124 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
125 virtual void SAL_CALL
removeModifyListener(
126 const ::com::sun::star::uno::Reference
<
127 ::com::sun::star::util::XModifyListener
> & xListener
)
128 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
130 // XPropertyContainer
131 virtual void SAL_CALL
addProperty( const OUString
& Name
, ::sal_Int16 Attributes
, const ::com::sun::star::uno::Any
& DefaultValue
) throw (::com::sun::star::beans::PropertyExistException
, ::com::sun::star::beans::IllegalTypeException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
132 virtual void SAL_CALL
removeProperty( const OUString
& Name
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::NotRemoveableException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
135 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> SAL_CALL
getPropertyValues( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
136 virtual void SAL_CALL
setPropertyValues( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aProps
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
139 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
140 virtual void SAL_CALL
setPropertyValue(const rtl::OUString
& p1
, const com::sun::star::uno::Any
& p2
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
141 { OPropertyBag_PBase::setPropertyValue(p1
, p2
); }
142 virtual com::sun::star::uno::Any SAL_CALL
getPropertyValue(const rtl::OUString
& p1
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
143 { return OPropertyBag_PBase::getPropertyValue(p1
); }
144 virtual void SAL_CALL
addPropertyChangeListener(const rtl::OUString
& p1
, const com::sun::star::uno::Reference
<com::sun::star::beans::XPropertyChangeListener
>& p2
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
145 { OPropertyBag_PBase::addPropertyChangeListener(p1
, p2
); }
146 virtual void SAL_CALL
removePropertyChangeListener(const rtl::OUString
& p1
, const com::sun::star::uno::Reference
<com::sun::star::beans::XPropertyChangeListener
>& p2
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
147 { OPropertyBag_PBase::removePropertyChangeListener(p1
, p2
); }
148 virtual void SAL_CALL
addVetoableChangeListener(const rtl::OUString
& p1
, const com::sun::star::uno::Reference
<com::sun::star::beans::XVetoableChangeListener
>& p2
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
149 { OPropertyBag_PBase::addVetoableChangeListener(p1
, p2
); }
150 virtual void SAL_CALL
removeVetoableChangeListener(const rtl::OUString
& p1
, const com::sun::star::uno::Reference
<com::sun::star::beans::XVetoableChangeListener
>& p2
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
151 { OPropertyBag_PBase::removeVetoableChangeListener(p1
, p2
); }
154 virtual sal_Bool SAL_CALL
has( const ::com::sun::star::uno::Any
& aElement
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
155 virtual void SAL_CALL
insert( const ::com::sun::star::uno::Any
& aElement
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::ElementExistException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
156 virtual void SAL_CALL
remove( const ::com::sun::star::uno::Any
& aElement
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
158 // XEnumerationAccess (base of XSet)
159 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
161 // XElementAccess (basf of XEnumerationAccess
162 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
163 virtual sal_Bool SAL_CALL
hasElements( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
164 /** === UNO interface implementations == **/
167 virtual ::com::sun::star::uno::Any
getPropertyDefaultByHandle( sal_Int32 _nHandle
) const SAL_OVERRIDE
;
169 // OPropertyStateHelper
170 virtual ::com::sun::star::beans::PropertyState
getPropertyStateByHandle( sal_Int32 _nHandle
) SAL_OVERRIDE
;
172 // OPropertySetHelper
173 virtual void SAL_CALL
getFastPropertyValue( ::com::sun::star::uno::Any
& rValue
, sal_Int32 nHandle
) const SAL_OVERRIDE
;
174 virtual sal_Bool SAL_CALL
convertFastPropertyValue( ::com::sun::star::uno::Any
& rConvertedValue
, ::com::sun::star::uno::Any
& rOldValue
, sal_Int32 nHandle
, const ::com::sun::star::uno::Any
& rValue
) throw (css::lang::IllegalArgumentException
, css::beans::UnknownPropertyException
) SAL_OVERRIDE
;
175 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
, std::exception
) SAL_OVERRIDE
;
176 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() SAL_OVERRIDE
;
178 // IEventNotificationHook
179 virtual void fireEvents(
180 sal_Int32
* pnHandles
,
183 bool bIgnoreRuntimeExceptionsWhileFiring
) SAL_OVERRIDE
;
185 void SAL_CALL
setModifiedImpl( bool bModified
,
186 bool bIgnoreRuntimeExceptionsWhileFiring
);
189 /** finds a free property handle
193 sal_Int32
findFreeHandle() const;
195 /** implements the setPropertyValues method
197 the property values to set
199 @throws PropertyVetoException
200 if the XMultiPropertySet::setPropertyValues call does so
202 @throws ::com::sun::star::lang::IllegalArgumentException
203 if the XMultiPropertySet::setPropertyValues call does so
205 @throws ::com::sun::star::lang::WrappedTargetException
206 if the XMultiPropertySet::setPropertyValues call does so
208 @throws ::com::sun::star::uno::RuntimeException
209 if the XMultiPropertySet::setPropertyValues call does so
211 @throws ::com::sun::star::beans::UnknownPropertyException
212 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
215 @throws ::com::sun::star::lang::WrappedTargetException
216 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
219 void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rProps
);
222 using ::cppu::OPropertySetHelper::getPropertyValues
;
223 using ::cppu::OPropertySetHelper::setPropertyValues
;
224 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
228 } // namespace comphelper
231 #endif // INCLUDED_COMPHELPER_SOURCE_PROPERTY_OPROPERTYBAG_HXX
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */