Line data Source code
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_CPPUHELPER_PROPERTYSETMIXIN_HXX
21 : #define INCLUDED_CPPUHELPER_PROPERTYSETMIXIN_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include <exception>
26 :
27 : #include <com/sun/star/beans/PropertyVetoException.hpp>
28 : #include <com/sun/star/beans/UnknownPropertyException.hpp>
29 : #include <com/sun/star/beans/XFastPropertySet.hpp>
30 : #include <com/sun/star/beans/XPropertyAccess.hpp>
31 : #include <com/sun/star/beans/XPropertySet.hpp>
32 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 : #include <com/sun/star/lang/WrappedTargetException.hpp>
34 : #include <com/sun/star/uno/Reference.hxx>
35 : #include <com/sun/star/uno/RuntimeException.hpp>
36 : #include <com/sun/star/uno/Sequence.hxx>
37 : #include <sal/types.h>
38 : #include <cppuhelper/cppuhelperdllapi.h>
39 :
40 : namespace com { namespace sun { namespace star {
41 : namespace beans {
42 : class XPropertyChangeListener;
43 : class XPropertySetInfo;
44 : class XVetoableChangeListener;
45 : struct PropertyValue;
46 : }
47 : namespace uno {
48 : class Any;
49 : class Type;
50 : class XComponentContext;
51 : }
52 : } } }
53 : namespace rtl { class OUString; }
54 :
55 : namespace cppu {
56 :
57 : template< typename T > class PropertySetMixin;
58 :
59 : // Suppress warnings about virtual functions but non-virtual destructor:
60 : #if defined _MSC_VER
61 : #pragma warning(push)
62 : #pragma warning(disable: 4265)
63 : #endif
64 :
65 : /**
66 : @short A helper base class for <code>cppu::PropertySetMixin</code>.
67 :
68 : See the documentation of <code>cppu::PropertySetMixin</code> for
69 : further details.
70 :
71 : That <code>cppu::PropertySetMixin</code> is derived from this
72 : base class should be considered an implementation detail. The functionality
73 : of <code>cppu::PropertySetMixin</code> that is inherited from this base
74 : class and is visible to subclasses of
75 : <code>cppu::PropertySetMixin</code> should be treated by such
76 : subclasses as being provided by <code>cppu::PropertySetMixin</code>
77 : directly (e.g., in such subclasses, use
78 : “<code>PropertySetMixin::Implements</code>” instead of
79 : “<code>PropertySetMixinImpl::Implements</code>”).
80 :
81 : @since UDK 3.2.1
82 : */
83 : #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY && HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE \
84 : && !defined __clang__
85 : #pragma GCC diagnostic push
86 : #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
87 : #endif
88 : class CPPUHELPER_DLLPUBLIC PropertySetMixinImpl:
89 : public com::sun::star::beans::XPropertySet,
90 : public com::sun::star::beans::XFastPropertySet,
91 : public com::sun::star::beans::XPropertyAccess
92 : {
93 : protected:
94 : /**
95 : @short Flags used by subclasses of
96 : <code>cppu::PropertySetMixin</code> to specify what UNO interface
97 : types shall be supported.
98 : */
99 : enum Implements {
100 : /**
101 : @short Flag specifying that the UNO interface type
102 : <code>com::sun::star::beans::XPropertySet</code> shall be supported.
103 : */
104 : IMPLEMENTS_PROPERTY_SET = 1,
105 :
106 : /**
107 : @short Flag specifying that the UNO interface type
108 : <code>com::sun::star::beans::XFastPropertySet</code> shall be
109 : supported.
110 : */
111 : IMPLEMENTS_FAST_PROPERTY_SET = 2,
112 :
113 : /**
114 : @short Flag specifying that the UNO interface type
115 : <code>com::sun::star::beans::XPropertyAccess</code> shall be
116 : supported.
117 : */
118 : IMPLEMENTS_PROPERTY_ACCESS = 4
119 : };
120 :
121 : /**
122 : @short A class used by subclasses of
123 : <code>cppu::PropertySetMixin</code> when implementing UNO interface
124 : type attribute setter functions.
125 :
126 : This class is not thread safe; that is, the constructor,
127 : <code>notify</code>, and the destructor must be called from the same
128 : thread.
129 :
130 : See <code>cppu::PropertySetMixinImpl::prepareSet</code> for
131 : further details.
132 : */
133 : class CPPUHELPER_DLLPUBLIC BoundListeners {
134 : public:
135 : /**
136 : @short The constructor.
137 :
138 : May throw <code>std::bad_alloc</code>.
139 : */
140 : BoundListeners();
141 :
142 : /**
143 : @short The destructor.
144 :
145 : Does not throw.
146 : */
147 : ~BoundListeners();
148 :
149 : /**
150 : @short Notifies any
151 : <code>com::sun::star::beans::XPropertyChangeListener</code>s.
152 :
153 : May throw <code>com::sun::star::uno::RuntimeException</code>
154 : and <code>std::bad_alloc</code>.
155 :
156 : See <code>cppu::PropertySetMixinImpl::prepareSet</code>
157 : for further details.
158 : */
159 : void notify() const;
160 :
161 : private:
162 : BoundListeners( const BoundListeners&); // not defined
163 : void operator=( const BoundListeners&); // not defined
164 :
165 : class Impl;
166 : Impl * m_impl;
167 :
168 : friend class PropertySetMixinImpl;
169 : };
170 :
171 : /**
172 : @short A function used by subclasses of
173 : <code>cppu::PropertySetMixin</code> when implementing UNO interface
174 : type attribute setter functions.
175 :
176 : First, this function checks whether this instance has already been
177 : disposed (see <code>cppu::PropertySetMixinImpl::dispose</code>),
178 : and throws a <code>com::sun::star::lang::DisposedException</code> if
179 : applicable. For a constrained attribute (whose setter can explicitly
180 : raise <code>com::sun::star::beans::PropertyVetoException</code>), this
181 : function notifies any
182 : <code>com::sun::star::beans::XVetoableChangeListener</code>s. For a
183 : bound attribute, this function modifies the passed-in
184 : <code>boundListeners</code> so that it can afterwards be used to notify
185 : any <code>com::sun::star::beans::XPropertyChangeListener</code>s. This
186 : function should be called before storing the new attribute value, and
187 : <code>boundListeners->notify()</code> should be called exactly once after
188 : storing the new attribute value (in case the attribute is bound;
189 : otherwise, calling <code>boundListeners->notify()</code> is ignored).
190 : Furthermore, <code>boundListeners->notify()</code> and this function have
191 : to be called from the same thread.
192 :
193 : May throw
194 : <code>com::sun::star::beans::PropertyVetoException</code>,
195 : <code>com::sun::star::uno::RuntimeException</code> (and
196 : <code>com::sun::star::lang::DisposedException</code> in particular), and
197 : <code>std::bad_alloc</code>.
198 :
199 : @param propertyName the name of the property (which is the same as the
200 : name of the attribute that is going to be set)
201 :
202 : @param oldValue the property value corresponding to the old attribute
203 : value. This is only used as
204 : <code>com::sun::star::beans::PropertyChangeEvent::OldValue</code>, which
205 : is rather useless, anyway (see “Using the Observer Pattern”
206 : in <a href="http://tools.openoffice.org/CodingGuidelines.sxw">
207 : OpenOffice.org Coding Guidelines</a>). If the attribute
208 : that is going to be set is neither bound nor constrained, or if
209 : <code>com::sun::star::beans::PropertyChangeEvent::OldValue</code> should
210 : not be set, a <code>VOID</code> <code>Any</code> can be used instead.
211 :
212 : @param newValue the property value corresponding to the new
213 : attribute value. This is only used as
214 : <code>com::sun::star::beans::PropertyChangeEvent::NewValue</code>, which
215 : is rather useless, anyway (see “Using the Observer Pattern”
216 : in <a href="http://tools.openoffice.org/CodingGuidelines.sxw">
217 : OpenOffice.org Coding Guidelines</a>), <em>unless</em> the
218 : attribute that is going to be set is constrained. If the attribute
219 : that is going to be set is neither bound nor constrained, or if it is
220 : only bound but
221 : <code>com::sun::star::beans::PropertyChangeEvent::NewValue</code> should
222 : not be set, a <code>VOID</code> <code>Any</code> can be used instead.
223 :
224 : @param boundListeners a pointer to a fresh
225 : <code>cppu::PropertySetMixinImpl::BoundListeners</code> instance
226 : (which has not been passed to this function before, and on which
227 : <code>notify</code> has not yet been called); may only be null if the
228 : attribute that is going to be set is not bound
229 : */
230 : void prepareSet(
231 : rtl::OUString const & propertyName,
232 : com::sun::star::uno::Any const & oldValue,
233 : com::sun::star::uno::Any const & newValue,
234 : BoundListeners * boundListeners);
235 :
236 : /**
237 : @short Mark this instance as being disposed.
238 :
239 : See <code>com::sun::star::lang::XComponent</code> for the general
240 : concept of disposing UNO objects. On the first call to this function,
241 : all registered listeners
242 : (<code>com::sun::star::beans::XPropertyChangeListener</code>s and
243 : <code>com::sun::star::beans::XVetoableChangeListener</code>s) are
244 : notified of the disposing source. Any subsequent calls to this function
245 : are ignored.
246 :
247 : May throw <code>com::sun::star::uno::RuntimeException</code> and
248 : <code>std::bad_alloc</code>.
249 : */
250 : void dispose();
251 :
252 : /**
253 : @short A function used by subclasses of
254 : <code>cppu::PropertySetMixin</code> when implementing
255 : <code>com::sun::star::uno::XInterface::queryInterface</code>.
256 :
257 : This function checks for support of any of the UNO interface types
258 : specified in the call of the <code>cppu::PropertySetMixin</code>
259 : constructor. It does not check for any other UNO interface types (not
260 : even for <code>com::sun::star::uno::XInterface</code>), and should not
261 : be used directly as the implementation of
262 : <code>com::sun::star::uno::XInterface::queryInterface</code> of this UNO
263 : object.
264 : */
265 : virtual com::sun::star::uno::Any SAL_CALL queryInterface(
266 : com::sun::star::uno::Type const & type)
267 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
268 :
269 : // @see com::sun::star::beans::XPropertySet::getPropertySetInfo
270 : virtual
271 : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >
272 : SAL_CALL getPropertySetInfo()
273 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
274 :
275 : // @see com::sun::star::beans::XPropertySet::setPropertyValue
276 : virtual void SAL_CALL setPropertyValue(
277 : rtl::OUString const & propertyName,
278 : com::sun::star::uno::Any const & value)
279 : throw (
280 : com::sun::star::beans::UnknownPropertyException,
281 : com::sun::star::beans::PropertyVetoException,
282 : com::sun::star::lang::IllegalArgumentException,
283 : com::sun::star::lang::WrappedTargetException,
284 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
285 :
286 : // @see com::sun::star::beans::XPropertySet::getPropertyValue
287 : virtual com::sun::star::uno::Any SAL_CALL getPropertyValue(
288 : rtl::OUString const & propertyName)
289 : throw (
290 : com::sun::star::beans::UnknownPropertyException,
291 : com::sun::star::lang::WrappedTargetException,
292 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
293 :
294 : /**
295 : @short Adds a
296 : <code>com::sun::star::beans::XPropertyChangeListener</code>.
297 :
298 : If a listener is added more than once, it will receive all
299 : relevant notifications multiple times.
300 :
301 : @see com::sun::star::beans::XPropertySet::addPropertyChangeListener
302 : */
303 : virtual void SAL_CALL addPropertyChangeListener(
304 : rtl::OUString const & propertyName,
305 : com::sun::star::uno::Reference<
306 : com::sun::star::beans::XPropertyChangeListener > const & listener)
307 : throw (
308 : com::sun::star::beans::UnknownPropertyException,
309 : com::sun::star::lang::WrappedTargetException,
310 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
311 :
312 : // @see com::sun::star::beans::XPropertySet::removePropertyChangeListener
313 : virtual void SAL_CALL removePropertyChangeListener(
314 : rtl::OUString const & propertyName,
315 : com::sun::star::uno::Reference<
316 : com::sun::star::beans::XPropertyChangeListener > const & listener)
317 : throw (
318 : com::sun::star::beans::UnknownPropertyException,
319 : com::sun::star::lang::WrappedTargetException,
320 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
321 :
322 : /**
323 : @short Adds a
324 : <code>com::sun::star::beans::XVetoableChangeListener</code>.
325 :
326 : If a listener is added more than once, it will receive all
327 : relevant notifications multiple times.
328 :
329 : @see com::sun::star::beans::XPropertySet::addVetoableChangeListener
330 : */
331 : virtual void SAL_CALL addVetoableChangeListener(
332 : rtl::OUString const & propertyName,
333 : com::sun::star::uno::Reference<
334 : com::sun::star::beans::XVetoableChangeListener > const & listener)
335 : throw (
336 : com::sun::star::beans::UnknownPropertyException,
337 : com::sun::star::lang::WrappedTargetException,
338 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
339 :
340 : // @see com::sun::star::beans::XPropertySet::removeVetoableChangeListener
341 : virtual void SAL_CALL removeVetoableChangeListener(
342 : rtl::OUString const & propertyName,
343 : com::sun::star::uno::Reference<
344 : com::sun::star::beans::XVetoableChangeListener > const & listener)
345 : throw (
346 : com::sun::star::beans::UnknownPropertyException,
347 : com::sun::star::lang::WrappedTargetException,
348 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
349 :
350 : // @see com::sun::star::beans::XFastPropertySet::setFastPropertyValue
351 : virtual void SAL_CALL setFastPropertyValue(
352 : sal_Int32 handle, com::sun::star::uno::Any const & value)
353 : throw (
354 : com::sun::star::beans::UnknownPropertyException,
355 : com::sun::star::beans::PropertyVetoException,
356 : com::sun::star::lang::IllegalArgumentException,
357 : com::sun::star::lang::WrappedTargetException,
358 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
359 :
360 : // @see com::sun::star::beans::XFastPropertySet::getFastPropertyValue
361 : virtual com::sun::star::uno::Any SAL_CALL getFastPropertyValue(
362 : sal_Int32 handle)
363 : throw (
364 : com::sun::star::beans::UnknownPropertyException,
365 : com::sun::star::lang::WrappedTargetException,
366 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
367 :
368 : // @see com::sun::star::beans::XPropertyAccess::getPropertyValues
369 : virtual
370 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
371 : SAL_CALL getPropertyValues()
372 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
373 :
374 : // @see com::sun::star::beans::XPropertyAccess::setPropertyValues
375 : virtual void SAL_CALL setPropertyValues(
376 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
377 : const & props)
378 : throw (
379 : com::sun::star::beans::UnknownPropertyException,
380 : com::sun::star::beans::PropertyVetoException,
381 : com::sun::star::lang::IllegalArgumentException,
382 : com::sun::star::lang::WrappedTargetException,
383 : com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
384 :
385 : private:
386 : PropertySetMixinImpl( const PropertySetMixinImpl&); // not defined
387 : void operator=( const PropertySetMixinImpl&); // not defined
388 :
389 : PropertySetMixinImpl(
390 : com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
391 : const & context,
392 : Implements implements,
393 : com::sun::star::uno::Sequence< rtl::OUString > const & absentOptional,
394 : com::sun::star::uno::Type const & type);
395 :
396 : class Impl;
397 : Impl * m_impl;
398 :
399 : friend class Impl;
400 : template< typename T > friend class PropertySetMixin;
401 :
402 : ~PropertySetMixinImpl();
403 :
404 : void checkUnknown(rtl::OUString const & propertyName);
405 : };
406 : #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY && HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE \
407 : && !defined __clang__
408 : #pragma GCC diagnostic pop
409 : #endif
410 :
411 : /**
412 : @short A helper mixin to implement certain UNO interfaces related to property
413 : set handling on top of the attributes of a given UNO interface type.
414 :
415 : The UNO interface type is specified by the type parameter
416 : <code>T</code> (which must correspond to a UNO interface type).
417 :
418 : No specializations of this class template should be added by client
419 : code.
420 :
421 : @since UDK 3.2.1
422 : */
423 : template< typename T > class PropertySetMixin: public PropertySetMixinImpl {
424 : protected:
425 : /**
426 : @short The constructor.
427 :
428 : May throw <code>com::sun::star::uno::RuntimeException</code> and
429 : <code>std::bad_alloc</code>.
430 :
431 : @param context the component context used by this class template; must
432 : not be null, and must supply the
433 : <code>com.sun.star.reflection.theCoreReflection</code> and
434 : <code>com.sun.star.reflection.theTypeDescriptionManager</code> singletons
435 :
436 : @param implements a combination of zero or more flags specifying what
437 : UNO interface types shall be supported
438 :
439 : @param absentOptional a list of optional properties that are not
440 : present, and should thus not be visible via
441 : <code>com::sun::star::beans::XPropertySet::getPropertySetInfo</code>,
442 : <code>com::sun::star::beans::XPropertySet::addPropertyChangeListener<!--
443 : --></code>, <code>com::sun::star::beans::XPropertySet::<!--
444 : -->removePropertyChangeListener</code>,
445 : <code>com::sun::star::beans::XPropertySet::addVetoableChangeListener<!--
446 : --></code>, and <code>com::sun::star::beans::XPropertySet::<!--
447 : -->removeVetoableChangeListener</code>. For consistency reasons, the
448 : given <code>absentOptional</code> should only contain the names of
449 : attributes that represent optional properties that are not present (that
450 : is, the attribute getters and setters always throw a
451 : <code>com::sun::star::beans::UnknownPropertyException</code>), and should
452 : contain each such name only once. If an optional property is not present
453 : (that is, the corresponding attribute getter and setter always throw a
454 : <code>com::sun::star::beans::UnknownPropertyException</code>) but is not
455 : contained in the given <code>absentOptional</code>, then it will be
456 : visible via
457 : <code>com::sun::star::beans::XPropertySet::getPropertySetInfo</code> as a
458 : <code>com::sun::star::beans::Property</code> with a set
459 : <code>com::sun::star::beans::PropertyAttribute::OPTIONAL</code>. If the
460 : given <code>implements</code> specifies that
461 : <code>com::sun::star::beans::XPropertySet</code> is not supported, then
462 : the given <code>absentOptional</code> is effectively ignored and can be
463 : empty.
464 : */
465 0 : PropertySetMixin(
466 : com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
467 : const & context,
468 : Implements implements,
469 : com::sun::star::uno::Sequence< rtl::OUString > const & absentOptional):
470 : PropertySetMixinImpl(
471 0 : context, implements, absentOptional, T::static_type())
472 0 : {}
473 :
474 : /**
475 : @short The destructor.
476 :
477 : Does not throw.
478 : */
479 0 : ~PropertySetMixin() {}
480 :
481 : private:
482 : PropertySetMixin( const PropertySetMixin&); // not defined
483 : void operator=( const PropertySetMixin&); // not defined
484 : };
485 :
486 : #if defined _MSC_VER
487 : #pragma warning(pop)
488 : #endif
489 :
490 : }
491 :
492 : #endif
493 :
494 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|