1*9877b273SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9877b273SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9877b273SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9877b273SAndrew Rist  * distributed with this work for additional information
6*9877b273SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9877b273SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9877b273SAndrew Rist  * "License"); you may not use this file except in compliance
9*9877b273SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9877b273SAndrew Rist  *
11*9877b273SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9877b273SAndrew Rist  *
13*9877b273SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9877b273SAndrew Rist  * software distributed under the License is distributed on an
15*9877b273SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9877b273SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9877b273SAndrew Rist  * specific language governing permissions and limitations
18*9877b273SAndrew Rist  * under the License.
19*9877b273SAndrew Rist  *
20*9877b273SAndrew Rist  *************************************************************/
21*9877b273SAndrew Rist 
22*9877b273SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef COMPHELPER_OPROPERTYBAG_HXX
25cdf0e10cSrcweir #define COMPHELPER_OPROPERTYBAG_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /** === begin UNO includes === **/
28cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
31cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyContainer.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
35cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
36cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp>
37cdf0e10cSrcweir /** === end UNO includes === **/
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <cppuhelper/implbase6.hxx>
40cdf0e10cSrcweir #include <comphelper/propstate.hxx>
41cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
42cdf0e10cSrcweir #include <comphelper/propertybag.hxx>
43cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
44cdf0e10cSrcweir #include <comphelper/uno3.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <map>
47cdf0e10cSrcweir #include <set>
48cdf0e10cSrcweir #include <memory>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //........................................................................
51cdf0e10cSrcweir namespace comphelper
52cdf0e10cSrcweir {
53cdf0e10cSrcweir //........................................................................
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     struct SAL_DLLPRIVATE UnoTypeLess : public ::std::unary_function< ::com::sun::star::uno::Type, bool >
56cdf0e10cSrcweir     {
operator ()comphelper::UnoTypeLess57cdf0e10cSrcweir         inline bool operator()( const ::com::sun::star::uno::Type& _rLHS, const ::com::sun::star::uno::Type& _rRHS ) const
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             return rtl_ustr_compare(
60cdf0e10cSrcweir                 _rLHS.getTypeLibType()->pTypeName->buffer,
61cdf0e10cSrcweir                 _rRHS.getTypeLibType()->pTypeName->buffer
62cdf0e10cSrcweir             ) < 0;
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir     };
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     typedef ::std::map< sal_Int32, ::com::sun::star::uno::Any >     MapInt2Any;
67cdf0e10cSrcweir     typedef ::std::set< ::com::sun::star::uno::Type, UnoTypeLess >  TypeBag;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     //====================================================================
70cdf0e10cSrcweir 	//= OPropertyBag
71cdf0e10cSrcweir 	//====================================================================
72cdf0e10cSrcweir     typedef ::cppu::WeakAggImplHelper6  <   ::com::sun::star::beans::XPropertyContainer
73cdf0e10cSrcweir                                         ,   ::com::sun::star::beans::XPropertyAccess
74cdf0e10cSrcweir                                         ,   ::com::sun::star::util::XModifiable
75cdf0e10cSrcweir                                         ,   ::com::sun::star::lang::XServiceInfo
76cdf0e10cSrcweir                                         ,   ::com::sun::star::lang::XInitialization
77cdf0e10cSrcweir                                         ,   ::com::sun::star::container::XSet
78cdf0e10cSrcweir                                         >   OPropertyBag_Base;
79cdf0e10cSrcweir     typedef ::comphelper::OPropertyStateHelper  OPropertyBag_PBase;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     class OPropertyBag  :public ::comphelper::OMutexAndBroadcastHelper  // must be before OPropertyBag_PBase
82cdf0e10cSrcweir                         ,public OPropertyBag_PBase
83cdf0e10cSrcweir                         ,public OPropertyBag_Base
84cdf0e10cSrcweir                         ,public ::cppu::IEventNotificationHook
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir     private:
87cdf0e10cSrcweir         ::comphelper::ComponentContext
88cdf0e10cSrcweir                         m_aContext;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         /// our IPropertyArrayHelper implementation
91cdf0e10cSrcweir         ::std::auto_ptr< ::cppu::OPropertyArrayHelper >
92cdf0e10cSrcweir                         m_pArrayHelper;
93cdf0e10cSrcweir         ::comphelper::PropertyBag
94cdf0e10cSrcweir                         m_aDynamicProperties;
95cdf0e10cSrcweir         /// set of allowed property types
96cdf0e10cSrcweir         TypeBag         m_aAllowedTypes;
97cdf0e10cSrcweir         /// should we automatically add properties which are tried to set, if they don't exist previously?
98cdf0e10cSrcweir         bool            m_bAutoAddProperties;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         /// for notification
101cdf0e10cSrcweir         ::cppu::OInterfaceContainerHelper m_NotifyListeners;
102cdf0e10cSrcweir         /// modify flag
103cdf0e10cSrcweir         bool            m_isModified;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     public:
106cdf0e10cSrcweir         OPropertyBag( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         // XServiceInfo - static versions
109cdf0e10cSrcweir 		static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
110cdf0e10cSrcweir 		static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
111cdf0e10cSrcweir 		static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
112cdf0e10cSrcweir                 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     protected:
115cdf0e10cSrcweir         virtual ~OPropertyBag();
116cdf0e10cSrcweir         DECLARE_XINTERFACE()
117cdf0e10cSrcweir         DECLARE_XTYPEPROVIDER()
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         /** === begin UNO interface implementations == **/
120cdf0e10cSrcweir         // XInitialization
121cdf0e10cSrcweir         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);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         // XServiceInfo
124cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
125cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
126cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         // XModifiable:
129cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL isModified(  )
130cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
131cdf0e10cSrcweir         virtual void SAL_CALL setModified( ::sal_Bool bModified )
132cdf0e10cSrcweir             throw (::com::sun::star::beans::PropertyVetoException,
133cdf0e10cSrcweir                     ::com::sun::star::uno::RuntimeException);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         // XModifyBroadcaster
136cdf0e10cSrcweir         virtual void SAL_CALL addModifyListener(
137cdf0e10cSrcweir             const ::com::sun::star::uno::Reference<
138cdf0e10cSrcweir                     ::com::sun::star::util::XModifyListener > & xListener)
139cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
140cdf0e10cSrcweir         virtual void SAL_CALL removeModifyListener(
141cdf0e10cSrcweir             const ::com::sun::star::uno::Reference<
142cdf0e10cSrcweir                     ::com::sun::star::util::XModifyListener > & xListener)
143cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         // XPropertyContainer
146cdf0e10cSrcweir         virtual void SAL_CALL addProperty( const ::rtl::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);
147cdf0e10cSrcweir         virtual void SAL_CALL removeProperty( const ::rtl::OUString& Name ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::NotRemoveableException, ::com::sun::star::uno::RuntimeException);
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         // XPropertyAccess
150cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues(  ) throw (::com::sun::star::uno::RuntimeException);
151cdf0e10cSrcweir         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);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         // XPropertySet
154cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         // XSet
157cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL has( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::uno::RuntimeException);
158cdf0e10cSrcweir         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);
159cdf0e10cSrcweir         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);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         // XEnumerationAccess (base of XSet)
162cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw (::com::sun::star::uno::RuntimeException);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         // XElementAccess (basf of XEnumerationAccess
165cdf0e10cSrcweir         virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException);
166cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException);
167cdf0e10cSrcweir         /** === UNO interface implementations == **/
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         // XPropertyState
170cdf0e10cSrcweir 	    virtual ::com::sun::star::uno::Any  getPropertyDefaultByHandle( sal_Int32 _nHandle ) const;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         // OPropertyStateHelper
173cdf0e10cSrcweir         virtual ::com::sun::star::beans::PropertyState  getPropertyStateByHandle( sal_Int32 _nHandle );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // OPropertySetHelper
176cdf0e10cSrcweir 	    virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
177cdf0e10cSrcweir         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);
178cdf0e10cSrcweir         virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception);
179cdf0e10cSrcweir         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         // IEventNotificationHook
182cdf0e10cSrcweir         virtual void fireEvents(
183cdf0e10cSrcweir             sal_Int32 * pnHandles,
184cdf0e10cSrcweir             sal_Int32 nCount,
185cdf0e10cSrcweir             sal_Bool bVetoable,
186cdf0e10cSrcweir             bool bIgnoreRuntimeExceptionsWhileFiring);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         void SAL_CALL setModifiedImpl( ::sal_Bool bModified,
189cdf0e10cSrcweir             bool bIgnoreRuntimeExceptionsWhileFiring);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     private:
192cdf0e10cSrcweir         /** finds a free property handle
193cdf0e10cSrcweir             @precond
194cdf0e10cSrcweir                 our mutex is locked
195cdf0e10cSrcweir         */
196cdf0e10cSrcweir         sal_Int32   findFreeHandle() const;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         /** implements the setPropertyValues method
199cdf0e10cSrcweir             @param _rProps
200cdf0e10cSrcweir                 the property values to set
201cdf0e10cSrcweir 
202cdf0e10cSrcweir             @throws PropertyVetoException
203cdf0e10cSrcweir                 if the XMultiPropertySet::setPropertyValues call does so
204cdf0e10cSrcweir 
205cdf0e10cSrcweir             @throws ::com::sun::star::lang::IllegalArgumentException
206cdf0e10cSrcweir                 if the XMultiPropertySet::setPropertyValues call does so
207cdf0e10cSrcweir 
208cdf0e10cSrcweir             @throws ::com::sun::star::lang::WrappedTargetException
209cdf0e10cSrcweir                 if the XMultiPropertySet::setPropertyValues call does so
210cdf0e10cSrcweir 
211cdf0e10cSrcweir             @throws ::com::sun::star::uno::RuntimeException
212cdf0e10cSrcweir                 if the XMultiPropertySet::setPropertyValues call does so
213cdf0e10cSrcweir 
214cdf0e10cSrcweir             @throws ::com::sun::star::beans::UnknownPropertyException
215cdf0e10cSrcweir                 if the XMultiPropertySet::setPropertyValues call does so, and <arg>_bTolerateUnknownProperties</arg>
216cdf0e10cSrcweir                 was set to <FALSE/>
217cdf0e10cSrcweir 
218cdf0e10cSrcweir             @throws ::com::sun::star::lang::WrappedTargetException
219cdf0e10cSrcweir                 if the XMultiPropertySet::setPropertyValues call did throw an exception not listed
220cdf0e10cSrcweir                 above
221cdf0e10cSrcweir         */
222cdf0e10cSrcweir         void impl_setPropertyValues_throw( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rProps );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     private:
225cdf0e10cSrcweir         OPropertyBag();                                 // never implemented
226cdf0e10cSrcweir         OPropertyBag( const OPropertyBag& );            // never implemented
227cdf0e10cSrcweir         OPropertyBag& operator=( const OPropertyBag& ); // never implemented
228cdf0e10cSrcweir     protected:
229cdf0e10cSrcweir         using ::cppu::OPropertySetHelper::getPropertyValues;
230cdf0e10cSrcweir         using ::cppu::OPropertySetHelper::setPropertyValues;
231cdf0e10cSrcweir         using ::cppu::OPropertySetHelper::getFastPropertyValue;
232cdf0e10cSrcweir     };
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //........................................................................
235cdf0e10cSrcweir } // namespace comphelper
236cdf0e10cSrcweir //........................................................................
237cdf0e10cSrcweir 
238cdf0e10cSrcweir #endif // COMPHELPER_OPROPERTYBAG_HXX
239