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