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