LibreOffice Module comphelper (master)  1
propagg.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_COMPHELPER_PROPAGG_HXX
21 #define INCLUDED_COMPHELPER_PROPAGG_HXX
22 
23 #include <config_options.h>
24 #include <com/sun/star/beans/Property.hpp>
25 #include <com/sun/star/beans/PropertyState.hpp>
26 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
27 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
28 #include <com/sun/star/lang/EventObject.hpp>
29 #include <comphelper/propstate.hxx>
31 
32 #include <map>
33 #include <memory>
34 #include <vector>
35 
36 
37 //= property helper classes
38 
39 
40 namespace comphelper
41 {
42 
43 
44 //= OPropertyAccessor
45 //= internal helper class for OPropertyArrayAggregationHelper
46 
47 namespace internal
48 {
50  {
51  sal_Int32 nOriginalHandle;
52  sal_Int32 nPos;
53  bool bAggregate;
54 
55  OPropertyAccessor(sal_Int32 _nOriginalHandle, sal_Int32 _nPos, bool _bAggregate)
56  :nOriginalHandle(_nOriginalHandle) ,nPos(_nPos) ,bAggregate(_bAggregate) { }
58  :nOriginalHandle(-1) ,nPos(-1) ,bAggregate(false) { }
59 
60  bool operator==(const OPropertyAccessor& rOb) const { return nPos == rOb.nPos; }
61  bool operator <(const OPropertyAccessor& rOb) const { return nPos < rOb.nPos; }
62  };
63 
64  typedef std::map< sal_Int32, OPropertyAccessor > PropertyAccessorMap;
65  typedef PropertyAccessorMap::const_iterator ConstPropertyAccessorMapIterator;
66 }
67 
68 
73 {
74 public:
80  virtual sal_Int32 getPreferredPropertyId(const OUString& _rName) = 0;
81 
82 protected:
84 };
85 
91 #define DEFAULT_AGGREGATE_PROPERTY_ID 10000
92 
94 {
95  friend class OPropertySetAggregationHelper;
96 
97  std::vector<css::beans::Property> m_aProperties;
99 
100 public:
124  OPropertyArrayAggregationHelper(const css::uno::Sequence< css::beans::Property>& _rProperties,
125  const css::uno::Sequence< css::beans::Property>& _rAggProperties,
126  IPropertyInfoService* _pInfoService = nullptr,
127  sal_Int32 _nFirstAggregateId = DEFAULT_AGGREGATE_PROPERTY_ID);
128 
129 
131  virtual sal_Bool SAL_CALL fillPropertyMembersByHandle( OUString* _pPropName, sal_Int16* _pAttributes,
132  sal_Int32 _nHandle) override ;
133 
135  virtual css::uno::Sequence< css::beans::Property> SAL_CALL getProperties() override;
137  virtual css::beans::Property SAL_CALL getPropertyByName(const OUString& _rPropertyName) override;
138 
140  virtual sal_Bool SAL_CALL hasPropertyByName(const OUString& _rPropertyName) override ;
142  virtual sal_Int32 SAL_CALL getHandleByName(const OUString & _rPropertyName) override;
144  virtual sal_Int32 SAL_CALL fillHandles( /*out*/sal_Int32* _pHandles, const css::uno::Sequence< OUString >& _rPropNames ) override;
145 
154  bool fillAggregatePropertyInfoByHandle(OUString* _pPropName, sal_Int32* _pOriginalHandle,
155  sal_Int32 _nHandle) const;
156 
159  bool getPropertyByHandle( sal_Int32 _nHandle, css::beans::Property& _rProperty ) const;
160 
161 
162  enum class PropertyOrigin
163  {
164  Aggregate,
165  Delegator,
166  Unknown
167  };
180  PropertyOrigin classifyProperty( const OUString& _rName );
181 
182 private:
183  const css::beans::Property* findPropertyByName(const OUString& _rName) const;
184 };
185 
186 
187 namespace internal
188 {
189  class PropertyForwarder;
190 }
191 
198 class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OPropertySetAggregationHelper :public OPropertyStateHelper
199  ,public css::beans::XPropertiesChangeListener
200  ,public css::beans::XVetoableChangeListener
201 {
202  friend class internal::PropertyForwarder;
203 
204 protected:
205  css::uno::Reference< css::beans::XPropertyState> m_xAggregateState;
206  css::uno::Reference< css::beans::XPropertySet> m_xAggregateSet;
207  css::uno::Reference< css::beans::XMultiPropertySet> m_xAggregateMultiSet;
208  css::uno::Reference< css::beans::XFastPropertySet> m_xAggregateFastSet;
209 
210  std::unique_ptr<internal::PropertyForwarder> m_pForwarder;
211  bool m_bListening : 1;
212 
213 public:
214  OPropertySetAggregationHelper( ::cppu::OBroadcastHelper& rBHelper );
215 
216  virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& aType) override;
217 
218 // XEventListener
219  virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
220 
221 // XFastPropertySet
222  virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any& aValue) override;
223  virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) override;
224 
225 // XPropertySet
226  virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override;
227  virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener) override;
228 
229 // XPropertiesChangeListener
230  virtual void SAL_CALL propertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent >& evt) override;
231 
232 // XVetoableChangeListener
233  virtual void SAL_CALL vetoableChange(const css::beans::PropertyChangeEvent& aEvent) override;
234 
235 // XMultiPropertySet
236  virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString >& PropertyNames, const css::uno::Sequence< css::uno::Any >& Values) override;
237  virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
238 
239 // XPropertyState
240  virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString& PropertyName) override;
241  virtual void SAL_CALL setPropertyToDefault(const OUString& PropertyName) override;
242  virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString& aPropertyName) override;
243 
244 // OPropertySetHelper
248  virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override = 0;
249 
253  virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue, sal_Int32 _nHandle, const css::uno::Any& _rValue ) override;
254 
258  virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const css::uno::Any& _rValue ) override;
259 
260 protected:
261  virtual ~OPropertySetAggregationHelper() override;
262 
263  virtual void SAL_CALL getFastPropertyValue(css::uno::Any& rValue, sal_Int32 nHandle) const override;
264  void disposing();
265 
266  sal_Int32 getOriginalHandle( sal_Int32 _nHandle ) const;
267  OUString getPropertyName( sal_Int32 _nHandle ) const;
268 
290  void declareForwardedProperty( sal_Int32 _nHandle );
291 
298  bool isCurrentlyForwardingProperty( sal_Int32 _nHandle ) const;
299 
306  virtual void forwardingPropertyValue( sal_Int32 _nHandle );
307 
314  virtual void forwardedPropertyValue( sal_Int32 _nHandle );
315 
319  void setAggregation(const css::uno::Reference< css::uno::XInterface >&);
320  void startListening();
321 };
322 
323 
324 } // namespace comphelper
325 
326 
327 #endif // INCLUDED_COMPHELPER_PROPAGG_HXX
328 
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const OPropertyAccessor &rOb) const
Definition: propagg.hxx:60
Unknown
PropertyAccessorMap::const_iterator ConstPropertyAccessorMapIterator
Definition: propagg.hxx:65
used as callback for an OPropertyArrayAggregationHelper
Definition: propagg.hxx:72
virtual sal_Int32 getPreferredPropertyId(const OUString &_rName)=0
get the preferred handle for the given property
OPropertyAccessor(sal_Int32 _nOriginalHandle, sal_Int32 _nPos, bool _bAggregate)
Definition: propagg.hxx:55
unsigned char sal_Bool
internal::PropertyAccessorMap m_aPropertyAccessors
Definition: propagg.hxx:98
#define DEFAULT_AGGREGATE_PROPERTY_ID
used for implementing a cppu::IPropertyArrayHelper for classes aggregating property sets ...
Definition: propagg.hxx:91
std::map< sal_Int32, OPropertyAccessor > PropertyAccessorMap
Definition: propagg.hxx:64
OUString getPropertyName(sal_Int32 nPropertyType)
bool operator<(const OPropertyAccessor &rOb) const
Definition: propagg.hxx:61
#define COMPHELPER_DLLPUBLIC
std::vector< css::beans::Property > m_aProperties
Definition: propagg.hxx:97
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
AnyEventRef aEvent