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 COMPHELPER_OPROPERTYBAG_HXX
21 #define COMPHELPER_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>
42 //........................................................................
45 //........................................................................
47 struct SAL_DLLPRIVATE 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 //====================================================================
63 //====================================================================
64 typedef ::cppu::WeakAggImplHelper5
< ::com::sun::star::beans::XPropertyBag
65 , ::com::sun::star::util::XModifiable
66 , ::com::sun::star::lang::XServiceInfo
67 , ::com::sun::star::lang::XInitialization
68 , ::com::sun::star::container::XSet
70 typedef ::comphelper::OPropertyStateHelper OPropertyBag_PBase
;
72 class OPropertyBag
:public ::comphelper::OMutexAndBroadcastHelper
// must be before OPropertyBag_PBase
73 ,public OPropertyBag_PBase
74 ,public OPropertyBag_Base
75 ,public ::cppu::IEventNotificationHook
76 ,private boost::noncopyable
79 /// our IPropertyArrayHelper implementation
80 ::std::auto_ptr
< ::cppu::OPropertyArrayHelper
>
82 ::comphelper::PropertyBag
84 /// set of allowed property types
85 TypeBag m_aAllowedTypes
;
86 /// should we automatically add properties which are tried to set, if they don't exist previously?
87 bool m_bAutoAddProperties
;
90 ::cppu::OInterfaceContainerHelper m_NotifyListeners
;
95 // XServiceInfo - static versions
96 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException
);
97 static OUString
getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException
);
98 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
99 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
103 virtual ~OPropertyBag();
105 DECLARE_XTYPEPROVIDER()
107 /** === begin UNO interface implementations == **/
109 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
);
112 virtual OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
);
113 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
114 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
117 virtual ::sal_Bool SAL_CALL
isModified( )
118 throw (::com::sun::star::uno::RuntimeException
);
119 virtual void SAL_CALL
setModified( ::sal_Bool bModified
)
120 throw (::com::sun::star::beans::PropertyVetoException
,
121 ::com::sun::star::uno::RuntimeException
);
123 // XModifyBroadcaster
124 virtual void SAL_CALL
addModifyListener(
125 const ::com::sun::star::uno::Reference
<
126 ::com::sun::star::util::XModifyListener
> & xListener
)
127 throw (::com::sun::star::uno::RuntimeException
);
128 virtual void SAL_CALL
removeModifyListener(
129 const ::com::sun::star::uno::Reference
<
130 ::com::sun::star::util::XModifyListener
> & xListener
)
131 throw (::com::sun::star::uno::RuntimeException
);
133 // XPropertyContainer
134 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
);
135 virtual void SAL_CALL
removeProperty( const OUString
& Name
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::NotRemoveableException
, ::com::sun::star::uno::RuntimeException
);
138 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> SAL_CALL
getPropertyValues( ) throw (::com::sun::star::uno::RuntimeException
);
139 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
);
142 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
143 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
)
144 { OPropertyBag_PBase::setPropertyValue(p1
, p2
); }
145 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
)
146 { return OPropertyBag_PBase::getPropertyValue(p1
); }
147 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
)
148 { OPropertyBag_PBase::addPropertyChangeListener(p1
, p2
); }
149 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
)
150 { OPropertyBag_PBase::removePropertyChangeListener(p1
, p2
); }
151 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
)
152 { OPropertyBag_PBase::addVetoableChangeListener(p1
, p2
); }
153 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
)
154 { OPropertyBag_PBase::removeVetoableChangeListener(p1
, p2
); }
157 virtual ::sal_Bool SAL_CALL
has( const ::com::sun::star::uno::Any
& aElement
) throw (::com::sun::star::uno::RuntimeException
);
158 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
);
159 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
);
161 // XEnumerationAccess (base of XSet)
162 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw (::com::sun::star::uno::RuntimeException
);
164 // XElementAccess (basf of XEnumerationAccess
165 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw (::com::sun::star::uno::RuntimeException
);
166 virtual ::sal_Bool SAL_CALL
hasElements( ) throw (::com::sun::star::uno::RuntimeException
);
167 /** === UNO interface implementations == **/
170 virtual ::com::sun::star::uno::Any
getPropertyDefaultByHandle( sal_Int32 _nHandle
) const;
172 // OPropertyStateHelper
173 virtual ::com::sun::star::beans::PropertyState
getPropertyStateByHandle( sal_Int32 _nHandle
);
175 // OPropertySetHelper
176 virtual void SAL_CALL
getFastPropertyValue( ::com::sun::star::uno::Any
& rValue
, sal_Int32 nHandle
) const;
177 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 (::com::sun::star::lang::IllegalArgumentException
);
178 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
);
179 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
181 // IEventNotificationHook
182 virtual void fireEvents(
183 sal_Int32
* pnHandles
,
186 bool bIgnoreRuntimeExceptionsWhileFiring
);
188 void SAL_CALL
setModifiedImpl( ::sal_Bool bModified
,
189 bool bIgnoreRuntimeExceptionsWhileFiring
);
192 /** finds a free property handle
196 sal_Int32
findFreeHandle() const;
198 /** implements the setPropertyValues method
200 the property values to set
202 @throws PropertyVetoException
203 if the XMultiPropertySet::setPropertyValues call does so
205 @throws ::com::sun::star::lang::IllegalArgumentException
206 if the XMultiPropertySet::setPropertyValues call does so
208 @throws ::com::sun::star::lang::WrappedTargetException
209 if the XMultiPropertySet::setPropertyValues call does so
211 @throws ::com::sun::star::uno::RuntimeException
212 if the XMultiPropertySet::setPropertyValues call does so
214 @throws ::com::sun::star::beans::UnknownPropertyException
215 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
218 @throws ::com::sun::star::lang::WrappedTargetException
219 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
222 void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rProps
);
225 using ::cppu::OPropertySetHelper::getPropertyValues
;
226 using ::cppu::OPropertySetHelper::setPropertyValues
;
227 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
230 //........................................................................
231 } // namespace comphelper
232 //........................................................................
234 #endif // COMPHELPER_OPROPERTYBAG_HXX
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */