/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
#ifndef INCLUDED_CPPUHELPER_PROPERTYSETMIXIN_HXX
#define INCLUDED_CPPUHELPER_PROPERTYSETMIXIN_HXX \
INCLUDED_CPPUHELPER_PROPERTYSETMIXIN_HXX
#include "sal/config.h"
#include "com/sun/star/beans/PropertyVetoException.hpp"
#include "com/sun/star/beans/UnknownPropertyException.hpp"
#include "com/sun/star/beans/XFastPropertySet.hpp"
#include "com/sun/star/beans/XPropertyAccess.hpp"
#include "com/sun/star/beans/XPropertySet.hpp"
#include "com/sun/star/lang/IllegalArgumentException.hpp"
#include "com/sun/star/lang/WrappedTargetException.hpp"
#include "com/sun/star/uno/Reference.hxx"
#include "com/sun/star/uno/RuntimeException.hpp"
#include "com/sun/star/uno/Sequence.hxx"
#include "sal/types.h"
/// @HTML
namespace com { namespace sun { namespace star {
namespace beans {
class XPropertyChangeListener;
class XPropertySetInfo;
class XVetoableChangeListener;
struct PropertyValue;
}
namespace uno {
class Any;
class Type;
class XComponentContext;
}
} } }
namespace rtl { class OUString; }
namespace cppu {
template< typename T > class PropertySetMixin;
// Suppress warnings about virtual functions but non-virtual destructor:
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4265)
#endif
/**
@short A helper base class for cppu::PropertySetMixin
.
@descr See the documentation of cppu::PropertySetMixin
for
further details.
@descr That cppu::PropertySetMixin
is derived from this
base class should be considered an implementation detail. The functionality
of cppu::PropertySetMixin
that is inherited from this base
class and is visible to subclasses of
cppu::PropertySetMixin
should be treated by such
subclasses as being provided by cppu::PropertySetMixin
directly (e.g., in such subclasses, use
“PropertySetMixin::Implements
” instead of
“PropertySetMixinImpl::Implements
”).
@since UDK 3.2.1
*/
class PropertySetMixinImpl:
public com::sun::star::beans::XPropertySet,
public com::sun::star::beans::XFastPropertySet,
public com::sun::star::beans::XPropertyAccess
{
protected:
/**
@short Flags used by subclasses of
cppu::PropertySetMixin
to specify what UNO interface
types shall be supported.
*/
enum Implements {
/**
@short Flag specifying that the UNO interface type
com::sun::star::beans::XPropertySet
shall be supported.
*/
IMPLEMENTS_PROPERTY_SET = 1,
/**
@short Flag specifying that the UNO interface type
com::sun::star::beans::XFastPropertySet
shall be
supported.
*/
IMPLEMENTS_FAST_PROPERTY_SET = 2,
/**
@short Flag specifying that the UNO interface type
com::sun::star::beans::XPropertyAccess
shall be
supported.
*/
IMPLEMENTS_PROPERTY_ACCESS = 4
};
/**
@short A class used by subclasses of
cppu::PropertySetMixin
when implementing UNO interface
type attribute setter functions.
@descr This class is not thread safe; that is, the constructor,
notify
, and the destructor must be called from the same
thread.
@descr See cppu::PropertySetMixinImpl::prepareSet
for
further details.
*/
class BoundListeners {
public:
/**
@short The constructor.
@descr May throw std::bad_alloc
.
*/
BoundListeners();
/**
@short The destructor.
@descr Does not throw.
*/
~BoundListeners();
/**
@short Notifies any
com::sun::star::beans::XPropertyChangeListener
s.
@descr May throw com::sun::star::uno::RuntimeException
and std::bad_alloc
.
@descr See cppu::PropertySetMixinImpl::prepareSet
for further details.
*/
void notify() const;
private:
BoundListeners( const BoundListeners&); // not defined
void operator=( const BoundListeners&); // not defined
class Impl;
Impl * m_impl;
friend class PropertySetMixinImpl;
};
/**
@short A function used by subclasses of
cppu::PropertySetMixin
when implementing UNO interface
type attribute setter functions.
@descr First, this function checks whether this instance has already been
disposed (see cppu::PropertySetMixinImpl::dispose
),
and throws a com::sun::star::lang::DisposedException
if
applicable. For a constrained attribute (whose setter can explicitly
raise com::sun::star::beans::PropertyVetoException
), this
function notifies any
com::sun::star::beans::XVetoableChangeListener
s. For a
bound attribute, this function modifies the passed-in
boundListeners
so that it can afterwards be used to notify
any com::sun::star::beans::XPropertyChangeListener
s. This
function should be called before storing the new attribute value, and
boundListeners->notify()
should be called exactly once after
storing the new attribute value (in case the attribute is bound;
otherwise, calling boundListeners->notify()
is ignored).
Furthermore, boundListeners->notify()
and this function have
to be called from the same thread.
@descr May throw
com::sun::star::beans::PropertyVetoException
,
com::sun::star::uno::RuntimeException
(and
com::sun::star::lang::DisposedException
in particular), and
std::bad_alloc
.
@param propertyName the name of the property (which is the same as the
name of the attribute that is going to be set)
@param oldValue the property value corresponding to the old attribute
value. This is only used as
com::sun::star::beans::PropertyChangeEvent::OldValue
, which
is rather useless, anyway (see “Using the Observer Pattern”
in
OpenOffice.org Coding Guidelines). If the attribute
that is going to be set is neither bound nor constrained, or if
com::sun::star::beans::PropertyChangeEvent::OldValue
should
not be set, a VOID
Any
can be used instead.
@param newValue the property value corresponding to the new
attribute value. This is only used as
com::sun::star::beans::PropertyChangeEvent::NewValue
, which
is rather useless, anyway (see “Using the Observer Pattern”
in
OpenOffice.org Coding Guidelines), unless the
attribute that is going to be set is constrained. If the attribute
that is going to be set is neither bound nor constrained, or if it is
only bound but
com::sun::star::beans::PropertyChangeEvent::NewValue
should
not be set, a VOID
Any
can be used instead.
@param boundListeners a pointer to a fresh
cppu::PropertySetMixinImpl::BoundListeners
instance
(which has not been passed to this function before, and on which
notify
has not yet been called); may only be null if the
attribute that is going to be set is not bound
*/
void prepareSet(
rtl::OUString const & propertyName,
com::sun::star::uno::Any const & oldValue,
com::sun::star::uno::Any const & newValue,
BoundListeners * boundListeners);
/**
@short Mark this instance as being disposed.
@descr See com::sun::star::lang::XComponent
for the general
concept of disposing UNO objects. On the first call to this function,
all registered listeners
(com::sun::star::beans::XPropertyChangeListener
s and
com::sun::star::beans::XVetoableChangeListener
s) are
notified of the disposing source. Any subsequent calls to this function
are ignored.
@descr May throw com::sun::star::uno::RuntimeException
and
std::bad_alloc
.
*/
void dispose();
/**
@short A function used by subclasses of
cppu::PropertySetMixin
when implementing
com::sun::star::uno::XInterface::queryInterface
.
@descr This function checks for support of any of the UNO interface types
specified in the call of the cppu::PropertySetMixin
constructor. It does not check for any other UNO interface types (not
even for com::sun::star::uno::XInterface
), and should not
be used directly as the implementation of
com::sun::star::uno::XInterface::queryInterface
of this UNO
object.
*/
virtual com::sun::star::uno::Any SAL_CALL queryInterface(
com::sun::star::uno::Type const & type)
throw (com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XPropertySet::getPropertySetInfo
virtual
com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >
SAL_CALL getPropertySetInfo() throw (com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XPropertySet::setPropertyValue
virtual void SAL_CALL setPropertyValue(
rtl::OUString const & propertyName,
com::sun::star::uno::Any const & value)
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);
// @see com::sun::star::beans::XPropertySet::getPropertyValue
virtual com::sun::star::uno::Any SAL_CALL getPropertyValue(
rtl::OUString const & propertyName)
throw (
com::sun::star::beans::UnknownPropertyException,
com::sun::star::lang::WrappedTargetException,
com::sun::star::uno::RuntimeException);
/**
@short Adds a
com::sun::star::beans::XPropertyChangeListener
.
@descr If a listener is added more than once, it will receive all
relevant notifications multiple times.
@see com::sun::star::beans::XPropertySet::addPropertyChangeListener
*/
virtual void SAL_CALL addPropertyChangeListener(
rtl::OUString const & propertyName,
com::sun::star::uno::Reference<
com::sun::star::beans::XPropertyChangeListener > const & listener)
throw (
com::sun::star::beans::UnknownPropertyException,
com::sun::star::lang::WrappedTargetException,
com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XPropertySet::removePropertyChangeListener
virtual void SAL_CALL removePropertyChangeListener(
rtl::OUString const & propertyName,
com::sun::star::uno::Reference<
com::sun::star::beans::XPropertyChangeListener > const & listener)
throw (
com::sun::star::beans::UnknownPropertyException,
com::sun::star::lang::WrappedTargetException,
com::sun::star::uno::RuntimeException);
/**
@short Adds a
com::sun::star::beans::XVetoableChangeListener
.
@descr If a listener is added more than once, it will receive all
relevant notifications multiple times.
@see com::sun::star::beans::XPropertySet::addVetoableChangeListener
*/
virtual void SAL_CALL addVetoableChangeListener(
rtl::OUString const & propertyName,
com::sun::star::uno::Reference<
com::sun::star::beans::XVetoableChangeListener > const & listener)
throw (
com::sun::star::beans::UnknownPropertyException,
com::sun::star::lang::WrappedTargetException,
com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XPropertySet::removeVetoableChangeListener
virtual void SAL_CALL removeVetoableChangeListener(
rtl::OUString const & propertyName,
com::sun::star::uno::Reference<
com::sun::star::beans::XVetoableChangeListener > const & listener)
throw (
com::sun::star::beans::UnknownPropertyException,
com::sun::star::lang::WrappedTargetException,
com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XFastPropertySet::setFastPropertyValue
virtual void SAL_CALL setFastPropertyValue(
sal_Int32 handle, com::sun::star::uno::Any const & value)
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);
// @see com::sun::star::beans::XFastPropertySet::getFastPropertyValue
virtual com::sun::star::uno::Any SAL_CALL getFastPropertyValue(
sal_Int32 handle)
throw (
com::sun::star::beans::UnknownPropertyException,
com::sun::star::lang::WrappedTargetException,
com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XPropertyAccess::getPropertyValues
virtual
com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
SAL_CALL getPropertyValues() throw (com::sun::star::uno::RuntimeException);
// @see com::sun::star::beans::XPropertyAccess::setPropertyValues
virtual void SAL_CALL setPropertyValues(
com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
const & props)
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);
private:
PropertySetMixinImpl( const PropertySetMixinImpl&); // not defined
void operator=( const PropertySetMixinImpl&); // not defined
PropertySetMixinImpl(
com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
const & context,
Implements implements,
com::sun::star::uno::Sequence< rtl::OUString > const & absentOptional,
com::sun::star::uno::Type const & type);
class Impl;
Impl * m_impl;
friend class Impl;
template< typename T > friend class PropertySetMixin;
~PropertySetMixinImpl();
void checkUnknown(rtl::OUString const & propertyName);
};
/**
@short A helper mixin to implement certain UNO interfaces related to property
set handling on top of the attributes of a given UNO interface type.
@descr The UNO interface type is specified by the type parameter
T
(which must correspond to a UNO interface type).
@descr No specializations of this class template should be added by client
code.
@since UDK 3.2.1
*/
template< typename T > class PropertySetMixin: public PropertySetMixinImpl {
protected:
/**
@short The constructor.
@descr May throw com::sun::star::uno::RuntimeException
and
std::bad_alloc
.
@param context the component context used by this class template; must
not be null, and must supply the service
com.sun.star.reflection.CoreReflection
and the singleton
com.sun.star.reflection.theTypeDescriptionManager
@param implements a combination of zero or more flags specifying what
UNO interface types shall be supported
@param absentOptional a list of optional properties that are not
present, and should thus not be visible via
com::sun::star::beans::XPropertySet::getPropertySetInfo
,
com::sun::star::beans::XPropertySet::addPropertyChangeListener
, com::sun::star::beans::XPropertySet::removePropertyChangeListener
,
com::sun::star::beans::XPropertySet::addVetoableChangeListener
, and com::sun::star::beans::XPropertySet::removeVetoableChangeListener
. For consistency reasons, the
given absentOptional
should only contain the names of
attributes that represent optional properties that are not present (that
is, the attribute getters and setters always throw a
com::sun::star::beans::UnknownPropertyException
), and should
contain each such name only once. If an optional property is not present
(that is, the corresponding attribute getter and setter always throw a
com::sun::star::beans::UnknownPropertyException
) but is not
contained in the given absentOptional
, then it will be
visible via
com::sun::star::beans::XPropertySet::getPropertySetInfo
as a
com::sun::star::beans::Property
with a set
com::sun::star::beans::PropertyAttribute::OPTIONAL
. If the
given implements
specifies that
com::sun::star::beans::XPropertySet
is not supported, then
the given absentOptional
is effectively ignored and can be
empty.
*/
PropertySetMixin(
com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
const & context,
Implements implements,
com::sun::star::uno::Sequence< rtl::OUString > const & absentOptional):
PropertySetMixinImpl(
context, implements, absentOptional, T::static_type())
{}
/**
@short The destructor.
@descr Does not throw.
*/
~PropertySetMixin() {}
private:
PropertySetMixin( const PropertySetMixin&); // not defined
void operator=( const PropertySetMixin&); // not defined
};
#if defined _MSC_VER
#pragma warning(pop)
#endif
}
#endif