diff options
Diffstat (limited to 'include/comphelper')
106 files changed, 16803 insertions, 0 deletions
diff --git a/include/comphelper/ChainablePropertySet.hxx b/include/comphelper/ChainablePropertySet.hxx new file mode 100644 index 000000000000..2dfe5f3ca256 --- /dev/null +++ b/include/comphelper/ChainablePropertySet.hxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_CHAINABLEPROPERTYSET_HXX_ +#define _COMPHELPER_CHAINABLEPROPERTYSET_HXX_ + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <comphelper/PropertyInfoHash.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + class ChainablePropertySetInfo; +} + +/* + * A ChainablePropertySet has the following features: + * + * 1. It implements both the PropertySet and MultiPropertySet interfaces. + * 2. It can be 'included' in a MasterPropertySet to seamlessly appear as if + * if it's properties were in the master. + * + * To be used as a base class for PropertySets, the subclass must implement + * the 6 protected pure virtual functions. If a mutex is passed to the + * constructor, this is locked before any call to _getSingleValue or + * _setSingleValue and released after all processing has completed + * (including _postSetValues or _postGetValues ) + * + * Any MasterPropertySet implementations that can include an + * implementation of a given ChainablePropertySet must be + * declared as a 'friend' in the implementation of the ChainablePropertySet. + * + */ + +namespace comphelper +{ + class COMPHELPER_DLLPUBLIC ChainablePropertySet : public ::com::sun::star::beans::XPropertySet, + public ::com::sun::star::beans::XPropertyState, + public ::com::sun::star::beans::XMultiPropertySet + { + friend class MasterPropertySet; + protected: + ChainablePropertySetInfo *mpInfo; + osl::SolarMutex* mpMutex; + ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySetInfo > mxInfo; + + virtual void _preSetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _setSingleValue( const comphelper::PropertyInfo & rInfo, const ::com::sun::star::uno::Any &rValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _postSetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + + virtual void _preGetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _getSingleValue( const comphelper::PropertyInfo & rInfo, ::com::sun::star::uno::Any & rValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _postGetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + + virtual void _preGetPropertyState () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ); + virtual void _getPropertyState( const comphelper::PropertyInfo& rInfo, ::com::sun::star::beans::PropertyState& rState ) + throw(::com::sun::star::beans::UnknownPropertyException ); + virtual void _postGetPropertyState () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ); + + virtual void _setPropertyToDefault( const comphelper::PropertyInfo& rEntry ) + throw(::com::sun::star::beans::UnknownPropertyException ); + virtual ::com::sun::star::uno::Any _getPropertyDefault( const comphelper::PropertyInfo& rEntry ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ); + + public: + ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, osl::SolarMutex* pMutex = NULL ) + throw(); + virtual ~ChainablePropertySet() + throw(); + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) + 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); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + // XMultiPropertySet + virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues ) + throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertiesChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL firePropertiesChangeEvent( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException); + + // XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > SAL_CALL getPropertyStates( const ::com::sun::star::uno::Sequence< OUString >& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + }; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/ChainablePropertySetInfo.hxx b/include/comphelper/ChainablePropertySetInfo.hxx new file mode 100644 index 000000000000..ce28803036d5 --- /dev/null +++ b/include/comphelper/ChainablePropertySetInfo.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_ +#define _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_ + +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <comphelper/PropertyInfoHash.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/TypeGeneration.hxx> +#include "comphelper/comphelperdllapi.h" + +/* + * A ChainablePropertySetInfo is usually initialised with a pointer to the first element + * of a null-terminated static table of PropertyInfo structs. This is placed in a hash_map + * for fast access + * + */ +namespace comphelper +{ + class COMPHELPER_DLLPUBLIC ChainablePropertySetInfo: + public ::cppu::WeakImplHelper1< + ::com::sun::star::beans::XPropertySetInfo > + { + friend class ChainablePropertySet; + friend class MasterPropertySet; + protected: + PropertyInfoHash maMap; + com::sun::star::uno::Sequence < com::sun::star::beans::Property > maProperties; + public: + ChainablePropertySetInfo( PropertyInfo * pMap ) + throw(); + + virtual ~ChainablePropertySetInfo() + throw(); + + void add( PropertyInfo* pMap, sal_Int32 nCount = -1 ) + throw(); + void remove( const OUString& aName ) + throw(); + + // XPropertySetInfo + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties() + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) + throw(::com::sun::star::uno::RuntimeException); + }; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/IdPropArrayHelper.hxx b/include/comphelper/IdPropArrayHelper.hxx new file mode 100644 index 000000000000..497a39fd500d --- /dev/null +++ b/include/comphelper/IdPropArrayHelper.hxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef COMPHELPER_IDPROPERTYARRAYUSAGEHELPER_HXX +#define COMPHELPER_IDPROPERTYARRAYUSAGEHELPER_HXX + +#include <cppuhelper/component.hxx> +#include <osl/mutex.hxx> +#include <cppuhelper/interfacecontainer.hxx> +#include <osl/diagnose.h> +#include <comphelper/stl_types.hxx> +#include <rtl/instance.hxx> +#include <cppuhelper/propshlp.hxx> + +namespace cppu { class IPropertyArrayHelper; } + +namespace comphelper +{ + //************************************************************ + // OIdPropertyArrayUsageHelper + //************************************************************ + template <typename TYPE> struct OIdPropertyArrayUsageHelperMutex + : public rtl::Static< ::osl::Mutex, OIdPropertyArrayUsageHelperMutex<TYPE> > {}; + + typedef std::map< sal_Int32, ::cppu::IPropertyArrayHelper*, std::less< sal_Int32 > > OIdPropertyArrayMap; + template <class TYPE> + class OIdPropertyArrayUsageHelper + { + protected: + static sal_Int32 s_nRefCount; + static OIdPropertyArrayMap* s_pMap; + + public: + OIdPropertyArrayUsageHelper(); + virtual ~OIdPropertyArrayUsageHelper() + { + ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); + OSL_ENSURE(s_nRefCount > 0, "OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); + if (!--s_nRefCount) + { + // delete the element + for (OIdPropertyArrayMap::iterator i = s_pMap->begin(); i != s_pMap->end(); ++i) + delete (*i).second; + delete s_pMap; + s_pMap = NULL; + } + } + + /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the + class, which is created if neccessary. + */ + ::cppu::IPropertyArrayHelper* getArrayHelper(sal_Int32 nId); + + protected: + /** used to implement the creation of the array helper which is shared amongst all instances of the class. + This method needs to be implemented in derived classes. + <BR> + The method gets called with Mutex acquired. + <BR> + as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper + assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps. + @return an pointer to the newly created array helper. Must not be NULL. + */ + virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const = 0; + }; + + //------------------------------------------------------------------ + template<class TYPE> + sal_Int32 OIdPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0; + + template<class TYPE> + OIdPropertyArrayMap* OIdPropertyArrayUsageHelper< TYPE >::s_pMap = NULL; + + //------------------------------------------------------------------ + template <class TYPE> + OIdPropertyArrayUsageHelper<TYPE>::OIdPropertyArrayUsageHelper() + { + ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); + // create the map if necessary + if (s_pMap == NULL) + s_pMap = new OIdPropertyArrayMap(); + ++s_nRefCount; + } + + //------------------------------------------------------------------ + template <class TYPE> + ::cppu::IPropertyArrayHelper* OIdPropertyArrayUsageHelper<TYPE>::getArrayHelper(sal_Int32 nId) + { + OSL_ENSURE(s_nRefCount, "OIdPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); + ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); + // do we have the array already? + if (! (*s_pMap)[nId] ) + { + (*s_pMap)[nId] = createArrayHelper(nId); + OSL_ENSURE((*s_pMap)[nId], "OIdPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); + } + return (*s_pMap)[nId]; + } +} +#endif // COMPHELPER_IDPROPERTYARRAYUSAGEHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/InlineContainer.hxx b/include/comphelper/InlineContainer.hxx new file mode 100644 index 000000000000..b23574bbad58 --- /dev/null +++ b/include/comphelper/InlineContainer.hxx @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef INCLUDED_COMPHELPER_INLINE_CONTAINER_HXX +#define INCLUDED_COMPHELPER_INLINE_CONTAINER_HXX + +#include <com/sun/star/uno/Sequence.hxx> + +#include <vector> +#include <map> +#include <set> + +namespace comphelper +{ + +/** Creates a UNO-Sequence which contains an arbitrary number of elements. + Notice, that every call of the operator() issues a realloc, so this is not + suitable to create very large sequences. + + usage: + + uno::Sequence< t >( MakeSequence< t >( t_1 )( t_2 )...( t_n ) ); + */ +template < typename T > +class MakeSequence : public ::com::sun::star::uno::Sequence< T > +{ +public: + explicit MakeSequence(const T &a) + : ::com::sun::star::uno::Sequence< T >( 1 ) + { + this->operator[](0) = a; + } + MakeSequence& operator()(const T &a) + { + this->realloc( this->getLength() + 1 ); + this->operator[]( this->getLength() - 1 ) = a; + return *this; + } +}; + +// ---------------------------------------- + +/** Creates a vector which contains an arbitrary number of elements. + + usage: + + vector< t > aVec( MakeVector< t >( t_1 )( t_2 )...( t_n ) ); + */ +template < typename T > +class MakeVector : public ::std::vector< T > +{ +public: + explicit MakeVector(const T &a) + : ::std::vector< T >(1, a) + { + } + MakeVector &operator()(const T &a) + { + this->push_back(a); + return *this; + } +}; + +// ---------------------------------------- + +/** Creates a set which contains an arbitrary number of elements. + + usage: + + set< t > aSet( MakeSet< t >( t_1 )( t_2 )...( t_n ) ); + */ +template < typename T > +class MakeSet : public ::std::set< T > +{ +public: + explicit MakeSet(const T &a) + : ::std::set< T >() + { + this->insert(this->end(), a); + } + MakeSet &operator()(const T &a) + { + this->insert(this->end(), a); + return *this; + } +}; + +// ---------------------------------------- + +/** usage: + + map< k, v > aMap( MakeMap< k, v > + ( key_1, value_1 ) + ( key_2, value_2 ) + ( key_3, value_3 ) + ... + ( key_n, value_n ) + ); + */ +template < typename Key, typename Value > +class MakeMap : public ::std::map< Key, Value > +{ +private: + typedef typename ::std::map< Key, Value >::value_type value_type; +public: + explicit MakeMap( const Key &k, const Value &v ) + { + this->insert( value_type( k, v ) ); + } + MakeMap &operator()( const Key &k, const Value &v ) + { + this->insert( value_type( k, v ) ); + return *this; + } + + MakeMap &operator()( const MakeMap& rSource ) + { + this->insert(rSource.begin(),rSource.end()); + return *this; + } +}; + +} // namespace comphelper + +#endif +// INCLUDED_COMPHELPER_INLINE_CONTAINER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/MasterPropertySet.hxx b/include/comphelper/MasterPropertySet.hxx new file mode 100644 index 000000000000..266137fdb9b4 --- /dev/null +++ b/include/comphelper/MasterPropertySet.hxx @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_MASTERPROPERTYSETHELPER_HXX_ +#define _COMPHELPER_MASTERPROPERTYSETHELPER_HXX_ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <comphelper/PropertyInfoHash.hxx> +#include "comphelper/comphelperdllapi.h" +#include <map> + +namespace comphelper +{ + class MasterPropertySetInfo; + class ChainablePropertySet; + struct SlaveData + { + ChainablePropertySet * mpSlave; + ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > mxSlave; + sal_Bool mbInit; + SlaveData ( ChainablePropertySet *pSlave); + inline sal_Bool IsInit () { return mbInit;} + inline void SetInit ( sal_Bool bInit) { mbInit = bInit; } + }; +} +typedef std::map < sal_uInt8, comphelper::SlaveData* > SlaveMap; + +/* + * A MasterPropertySet implements all of the features of a ChainablePropertySet + * (it is not inherited from ChainablePropertySet to prevent MasterPropertySets + * being chained to each other), but also allows properties implemented in + * other ChainablePropertySets to be included as 'native' properties in a + * given MasterPropertySet implementation. These are registered using the + * 'registerSlave' method, and require that the implementation of the + * ChainablePropertySet and the implementation of the ChainablePropertySetInfo + * both declare the implementation of the MasterPropertySet as a friend. + */ +namespace comphelper +{ + class COMPHELPER_DLLPUBLIC MasterPropertySet : public ::com::sun::star::beans::XPropertySet, + public ::com::sun::star::beans::XPropertyState, + public ::com::sun::star::beans::XMultiPropertySet + { + protected: + MasterPropertySetInfo *mpInfo; + osl::SolarMutex* mpMutex; + sal_uInt8 mnLastId; + SlaveMap maSlaveMap; + ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySetInfo > mxInfo; + + virtual void _preSetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _setSingleValue( const comphelper::PropertyInfo & rInfo, const ::com::sun::star::uno::Any &rValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _postSetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + + virtual void _preGetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _getSingleValue( const comphelper::PropertyInfo & rInfo, ::com::sun::star::uno::Any & rValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ) = 0; + virtual void _postGetValues () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) = 0; + + virtual void _preGetPropertyState () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ); + virtual void _getPropertyState( const comphelper::PropertyInfo& rInfo, ::com::sun::star::beans::PropertyState& rState ) + throw(::com::sun::star::beans::UnknownPropertyException ); + virtual void _postGetPropertyState () + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ); + + virtual void _setPropertyToDefault( const comphelper::PropertyInfo& rEntry ) + throw(::com::sun::star::beans::UnknownPropertyException ); + virtual ::com::sun::star::uno::Any _getPropertyDefault( const comphelper::PropertyInfo& rEntry ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ); + + public: + MasterPropertySet( comphelper::MasterPropertySetInfo* pInfo, ::osl::SolarMutex* pMutex = NULL ) + throw(); + virtual ~MasterPropertySet() + throw(); + void registerSlave ( ChainablePropertySet *pNewSet ) + throw(); + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) + 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); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + // XMultiPropertySet + virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues ) + throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertiesChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL firePropertiesChangeEvent( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException); + + // XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > SAL_CALL getPropertyStates( const ::com::sun::star::uno::Sequence< OUString >& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + }; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/MasterPropertySetInfo.hxx b/include/comphelper/MasterPropertySetInfo.hxx new file mode 100644 index 000000000000..d2c772e2c5d5 --- /dev/null +++ b/include/comphelper/MasterPropertySetInfo.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_MASTERPROPERTYSETINFO_HXX_ +#define _COMPHELPER_MASTERPROPERTYSETINFO_HXX_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <comphelper/PropertyInfoHash.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/TypeGeneration.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + class COMPHELPER_DLLPUBLIC MasterPropertySetInfo: + public ::cppu::WeakImplHelper1< + ::com::sun::star::beans::XPropertySetInfo > + { + friend class MasterPropertySet; + protected: + PropertyDataHash maMap; + com::sun::star::uno::Sequence < com::sun::star::beans::Property > maProperties; + public: + MasterPropertySetInfo( PropertyInfo * pMap ) + throw(); + virtual ~MasterPropertySetInfo() + throw(); + void add( PropertyInfo* pMap, sal_Int32 nCount = -1, sal_uInt8 nMapId = 0 ) + throw(); + void add( PropertyInfoHash &rHash, sal_uInt8 nMapId ) + throw(); + + // XPropertySetInfo + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties() + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) + throw(::com::sun::star::uno::RuntimeException); + }; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/PropertyInfoHash.hxx b/include/comphelper/PropertyInfoHash.hxx new file mode 100644 index 000000000000..3241560b4a94 --- /dev/null +++ b/include/comphelper/PropertyInfoHash.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTYINFOHASH_HXX_ +#define _COMPHELPER_PROPERTYINFOHASH_HXX_ + +#include <rtl/ustring.hxx> +#include <comphelper/TypeGeneration.hxx> +#include <boost/unordered_map.hpp> +namespace comphelper +{ + struct PropertyInfo + { + const sal_Char* mpName; + sal_uInt16 mnNameLen; + sal_Int32 mnHandle; + CppuTypes meCppuType; + sal_Int16 mnAttributes; + sal_uInt8 mnMemberId; + }; + struct PropertyData + { + sal_uInt8 mnMapId; + PropertyInfo *mpInfo; + PropertyData ( sal_uInt8 nMapId, PropertyInfo *pInfo ) + : mnMapId ( nMapId ) + , mpInfo ( pInfo ) {} + }; + struct eqFunc + { + sal_Bool operator()( const OUString &r1, + const OUString &r2) const + { + return r1 == r2; + } + }; +} + +typedef boost::unordered_map < OUString, + ::comphelper::PropertyInfo*, + OUStringHash, + ::comphelper::eqFunc > PropertyInfoHash; +typedef boost::unordered_map < OUString, + ::comphelper::PropertyData*, + OUStringHash, + ::comphelper::eqFunc > PropertyDataHash; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/SelectionMultiplex.hxx b/include/comphelper/SelectionMultiplex.hxx new file mode 100644 index 000000000000..56e8375fd215 --- /dev/null +++ b/include/comphelper/SelectionMultiplex.hxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX +#define INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX + +#include <com/sun/star/view/XSelectionChangeListener.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <cppuhelper/implbase1.hxx> +#include "comphelper/comphelperdllapi.h" + +//========================================================================= +//= selection helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + class OSelectionChangeMultiplexer; + + //================================================================== + //= OSelectionChangeListener + //================================================================== + /// simple listener adapter for selections + class COMPHELPER_DLLPUBLIC OSelectionChangeListener + { + friend class OSelectionChangeMultiplexer; + + OSelectionChangeMultiplexer* m_pAdapter; + ::osl::Mutex& m_rMutex; + + public: + OSelectionChangeListener(::osl::Mutex& _rMutex) + : m_pAdapter(NULL), m_rMutex(_rMutex) { } + virtual ~OSelectionChangeListener(); + + virtual void _selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException); + + protected: + // pseudo-private. Making it private now could break compatibility + void setAdapter( OSelectionChangeMultiplexer* _pAdapter ); + }; + + //================================================================== + //= OSelectionChangeMultiplexer + //================================================================== + /// multiplexer for selection changes + class COMPHELPER_DLLPUBLIC OSelectionChangeMultiplexer :public cppu::WeakImplHelper1< ::com::sun::star::view::XSelectionChangeListener> + { + friend class OSelectionChangeListener; + ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier> m_xSet; + OSelectionChangeListener* m_pListener; + sal_Int32 m_nLockCount; + sal_Bool m_bListening : 1; + sal_Bool m_bAutoSetRelease : 1; + + OSelectionChangeMultiplexer(const OSelectionChangeMultiplexer&); + OSelectionChangeMultiplexer& operator=(const OSelectionChangeMultiplexer&); + protected: + virtual ~OSelectionChangeMultiplexer(); + public: + OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionSupplier>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException); + + // XSelectionChangeListener + virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); + + /// incremental lock + void lock(); + /// incremental unlock + void unlock(); + /// get the lock count + sal_Int32 locked() const { return m_nLockCount; } + + void dispose(); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // INCLUDED_COMPHELPER_SELECTION_MULTIPLEX_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/SettingsHelper.hxx b/include/comphelper/SettingsHelper.hxx new file mode 100644 index 000000000000..d623fa3e5494 --- /dev/null +++ b/include/comphelper/SettingsHelper.hxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_SETTINGSHELPER_HXX_ +#define _COMPHELPER_SETTINGSHELPER_HXX_ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase3.hxx> + +namespace comphelper +{ + class MasterPropertySet; + class MasterPropertySetInfo; + class ChainablePropertySet; + class ChainablePropertySetInfo; + + typedef cppu::WeakImplHelper3 + < + ::com::sun::star::beans::XPropertySet, + ::com::sun::star::beans::XMultiPropertySet, + ::com::sun::star::lang::XServiceInfo + > + HelperBaseNoState; + template < class ComphelperBase, class ComphelperBaseInfo > class SettingsHelperNoState : + public HelperBaseNoState, + public ComphelperBase + { + public: + SettingsHelperNoState ( ComphelperBaseInfo *pInfo, ::osl::SolarMutex* pMutex = NULL) + : ComphelperBase ( pInfo, pMutex ) + {} + virtual ~SettingsHelperNoState () throw( ) {} + com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type& aType ) throw (com::sun::star::uno::RuntimeException) + { return HelperBaseNoState::queryInterface( aType ); } + void SAL_CALL acquire( ) throw () + { HelperBaseNoState::acquire( ); } + void SAL_CALL release( ) throw () + { HelperBaseNoState::release( ); } + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) + throw(::com::sun::star::uno::RuntimeException) + { return ComphelperBase::getPropertySetInfo(); } + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) + 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) + { ComphelperBase::setPropertyValue ( aPropertyName, aValue ); } + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { return ComphelperBase::getPropertyValue ( PropertyName ); } + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { ComphelperBase::addPropertyChangeListener ( aPropertyName, xListener ); } + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { ComphelperBase::removePropertyChangeListener ( aPropertyName, aListener ); } + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { ComphelperBase::addVetoableChangeListener ( PropertyName, aListener ); } + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { ComphelperBase::removeVetoableChangeListener ( PropertyName, aListener ); } + + // XMultiPropertySet + virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues ) + throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) + { ComphelperBase::setPropertyValues ( aPropertyNames, aValues ); } + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames ) + throw(::com::sun::star::uno::RuntimeException) + { return ComphelperBase::getPropertyValues ( aPropertyNames ); } + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException) + { ComphelperBase::addPropertiesChangeListener ( aPropertyNames, xListener ); } + virtual void SAL_CALL removePropertiesChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException) + { ComphelperBase::removePropertiesChangeListener ( xListener ); } + virtual void SAL_CALL firePropertiesChangeEvent( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) + throw(::com::sun::star::uno::RuntimeException) + { ComphelperBase::firePropertiesChangeEvent ( aPropertyNames, xListener ); } + }; + typedef comphelper::SettingsHelperNoState + < + ::comphelper::MasterPropertySet, + ::comphelper::MasterPropertySetInfo + > + MasterHelperNoState; + typedef comphelper::SettingsHelperNoState + < + ::comphelper::ChainablePropertySet, + ::comphelper::ChainablePropertySetInfo + > + ChainableHelperNoState; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/TypeGeneration.hxx b/include/comphelper/TypeGeneration.hxx new file mode 100644 index 000000000000..0ced57b31714 --- /dev/null +++ b/include/comphelper/TypeGeneration.hxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_TYPEGENERATION_HXX_ +#define _COMPHELPER_TYPEGENERATION_HXX_ + +#include <sal/types.h> +#include "comphelper/comphelperdllapi.h" + +#define CPPU_E2T(type) ((com::sun::star::uno::Type*)type) + +namespace com { namespace sun { namespace star { namespace uno { + class Type; +} } } } +namespace comphelper +{ + enum CppuTypes + { + CPPUTYPE_UNKNOWN, // 0 == unknown == error!!!! + + CPPUTYPE_BOOLEAN, //getBooleanCppuType() + CPPUTYPE_INT8, //getCppuType( (sal_Int8*)0 ) + CPPUTYPE_INT16, //getCppuType( (sal_Int16*)0 ) + CPPUTYPE_INT32, //getCppuType( (sal_Int32*)0 ) + CPPUTYPE_DOUBLE, //getCppuType( (double*)0 ) + CPPUTYPE_FLOAT, //getCppuType( (float*)0 ) + CPPUTYPE_OUSTRING, //getCppuType( (OUString*)0 ) + + CPPUTYPE_FONTSLANT, //getCppuType( (FontSlant*)0 ) + CPPUTYPE_LOCALE, //getCppuType( (Locale*)0 ) + CPPUTYPE_PROPERTYVALUE, //getCppuType( (Sequence<PropertyValue>*)0 ) + CPPUTYPE_PROPERTYVALUES, //getCppuType( (Sequence<PropertyValues>*)0 ) + CPPUTYPE_BORDERLINE, //getCppuType( (table::BorderLine*)0 ) + CPPUTYPE_BREAK, //getCppuType( (style::BreakType*)0 ) + CPPUTYPE_GRAPHICLOC, //getCppuType( (style::GraphicLocation*)0 ) + CPPUTYPE_DROPCAPFMT, //getCppuType( (style::DropCapFormat*)0 ) + CPPUTYPE_LINESPACE, //getCppuType( (style::LineSpacing*)0 ) + CPPUTYPE_AWTSIZE, //getCppuType( (awt::Size*)0 ) + CPPUTYPE_SHADOWFMT, //getCppuType( (table::ShadowFormat*)0 ) + CPPUTYPE_TBLCOLSEP, //getCppuType( (Sequence<text::TableColumnSeparator>*)0 ) + CPPUTYPE_PNTSEQSEQ, //getCppuType( (PointSequenceSequence*)0 ) + CPPUTYPE_DOCIDXMRK, //getCppuType( (Sequence< Reference< XDocumentIndexMark > >*)0 ) + CPPUTYPE_SEQINT8, //getCppuType( (Sequence<sal_Int8>*)0 ) + CPPUTYPE_SEQTABSTOP, //getCppuType( (Sequence<style::TabStop>*)0 ) + CPPUTYPE_SEQANCHORTYPE, //getCppuType( (Sequence<text::TextContentAnchorType>*)0 ) + CPPUTYPE_SEQDEPTXTFLD, //getCppuType( (Sequence<Reference<XDependentTextField> >*)0 ) + CPPUTYPE_TXTCNTANCHOR, //getCppuType( (text::TextContentAnchorType*)0 ) + CPPUTYPE_WRAPTXTMODE, //getCppuType( (text::WrapTextMode*)0 ) + CPPUTYPE_LINESTYLE, //getCppuType( (drawing::LineStyle*)0 ) + CPPUTYPE_COLORMODE, //getCppuType( (drawing::ColorMode*)0 ) + CPPUTYPE_PAGESTYLELAY, //getCppuType( (style::PageStyleLayout*)0 ) + CPPUTYPE_VERTALIGN, //getCppuType( (style::VerticalAlignment*)0 ) + CPPUTYPE_TABLEBORDER, //getCppuType( (table::TableBorder*)0 ) + CPPUTYPE_TABLEBORDER2, //getCppuType( (table::TableBorder*)0 ) + CPPUTYPE_GRFCROP, //getCppuType( (text::GraphicCrop*)0 ) + CPPUTYPE_SECTFILELNK, //getCppuType( (text::SectionFileLink*)0 ) + CPPUTYPE_PAGENUMTYPE, //getCppuType( (const PageNumberType*)0 ) + CPPUTYPE_DATETIME, //getCppuType( (util::DateTime*)0 ) + CPPUTYPE_DATE, //getCppuType( (util::Date*)0 ) + + CPPUTYPE_REFINTERFACE, //getCppuType( (Reference<XInterface>*)0 ) + CPPUTYPE_REFIDXREPL, //getCppuType( (Reference<container::XIndexReplace>*)0 ) + CPPUTYPE_REFNAMECNT, //getCppuType( (Reference<container::XNameContainer>*)0 ) + CPPUTYPE_REFTEXTFRAME, //getCppuType( (Reference<text::XTextFrame>*)0 ) + CPPUTYPE_REFTEXTSECTION, //getCppuType( (Reference<text::XTextSection>*)0 ) + CPPUTYPE_REFFOOTNOTE, //getCppuType( (Reference<text::XFootnote>*)0 ) + CPPUTYPE_REFTEXT, //getCppuType( (Reference<text::XText>*)0 ) + CPPUTYPE_REFTEXTCOL, //getCppuType( (Reference<text::XTextColumns>*)0 ) + + CPPUTYPE_REFFORBCHARS, //getCppuType( (Reference<XForbiddenCharacters>*)0) + CPPUTYPE_REFIDXCNTNR, //getCppuType( (Reference<XIndexContainer>*)0) + CPPUTYPE_REFTEXTCNTNT, //getCppuType( (Reference<XTextContent>*)0) + CPPUTYPE_REFBITMAP, //getCppuType( (Reference<awt::XBitmap>*)0) + CPPUTYPE_REFNMREPLACE, //getCppuType( (Reference<container::XNameReplace>*)0) + CPPUTYPE_REFCELL, //getCppuType( (Reference<table::XCell>*)0) + CPPUTYPE_REFDOCINDEX, //getCppuType( (Reference<text::XDocumentIndex>*)0) + CPPUTYPE_REFDOCIDXMRK, //getCppuType( (Reference<text::XDocumentIndexMark>*)0) + CPPUTYPE_REFTXTFIELD, //getCppuType( (Reference<text::XTextField>*)0) + CPPUTYPE_REFTXTRANGE, //getCppuType( (Reference<text::XTextRange>*)0) + CPPUTYPE_REFTXTTABLE, //getCppuType( (Reference<text::XTextTable>*)0) + CPPUTYPE_AWTPOINT, //getCppuType( (awt::Point*)0 ) + CPPUTYPE_REFLIBCONTAINER, //getCppuType( (Reference< script::XLibraryContainer >*)0) + CPPUTYPE_SEQANY, //getCppuType( (Sequence< uno::Any >*)0) + CPPUTYPE_REFRESULTSET, //getCppuType( (Reference< sdbc::XResultSet >*)0) + CPPUTYPE_REFCONNECTION, //getCppuType( (Reference< sdbc::XConnection >*)0) + CPPUTYPE_REFMODEL, //getCppuType( (Reference< frame::XModel >*)0) + + CPPUTYPE_OUSTRINGS, //getCppuType( (Sequence<OUString>*)0 ) + CPPUTYPE_REFCOMPONENT, //getCppuType( (Reference< lang::XComponent >*)0 ) + // #i28749# + CPPUTYPE_TRANSFORMATIONINHORIL2R, //getCppuType( (drawing::HomogenMatrix3)* ) + CPPUTYPE_SEQNAMEDVALUE, //getCppuType( (Sequence<beans::NamedValue>*)0 ) + CPPUTYPE_REFXGRAPHIC, //getCppuType( Reference< graphic::XGraphic >*)0) + CPPUTYPE_TABLEBORDERDISTANCES, //getCppuType( (table::TableBorderDistances*)0 ) + CPPUTPYE_REFEMBEDDEDOBJECT, // XEmbeddedObject::static_type + CPPUTYPE_FILLSTYLE, //getCppuType( (drawing::FillStyle*)0 ) + CPPUTYPE_GRADIENT, //getCppuType( (awt::Gradient*)0 ) + + CPPUTYPE_END + }; + COMPHELPER_DLLPUBLIC void GenerateCppuType ( + CppuTypes eType, const com::sun::star::uno::Type*& pType ); +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessiblecomponenthelper.hxx b/include/comphelper/accessiblecomponenthelper.hxx new file mode 100644 index 000000000000..d0eabc27b807 --- /dev/null +++ b/include/comphelper/accessiblecomponenthelper.hxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_COMPONENT_HELPER_HXX +#define COMPHELPER_ACCESSIBLE_COMPONENT_HELPER_HXX + +#include <com/sun/star/accessibility/XAccessibleComponent.hpp> +#include <com/sun/star/accessibility/XAccessibleExtendedComponent.hpp> +#include <comphelper/accessiblecontexthelper.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/uno3.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= OCommonAccessibleComponent + //===================================================================== + /** base class encapsulating common functionality for the helper classes implementing + the XAccessibleComponent respectively XAccessibleExtendendComponent + */ + class COMPHELPER_DLLPUBLIC OCommonAccessibleComponent : public OAccessibleContextHelper + { + protected: + OCommonAccessibleComponent(); + /// see the respective base class ctor for an extensive comment on this, please + OCommonAccessibleComponent( IMutex* _pExternalLock ); + ~OCommonAccessibleComponent(); + + protected: + /// implements the calculation of the bounding rectangle - still waiting to be overwritten + virtual ::com::sun::star::awt::Rectangle SAL_CALL implGetBounds( ) throw (::com::sun::star::uno::RuntimeException) = 0; + + protected: + /** non-virtual versions of the methods which can be implemented using <method>implGetBounds</method> + note: getLocationOnScreen relies on a valid parent (XAccessibleContext::getParent()->getAccessibleContext()), + which itself implements XAccessibleComponent + */ + sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException); + ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException); + ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException); + ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); + ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException); + }; + + //===================================================================== + //= OAccessibleComponentHelper + //===================================================================== + + struct OAccessibleComponentHelper_Base : + public ::cppu::ImplHelper1< ::com::sun::star::accessibility::XAccessibleComponent > + { + protected: + ~OAccessibleComponentHelper_Base() {} + }; + + /** a helper class for implementing an AccessibleContext which at the same time + supports an XAccessibleComponent interface. + */ + class COMPHELPER_DLLPUBLIC OAccessibleComponentHelper + :public OCommonAccessibleComponent + ,public OAccessibleComponentHelper_Base + { + protected: + OAccessibleComponentHelper( ); + /// see the respective base class ctor for an extensive comment on this, please + OAccessibleComponentHelper( IMutex* _pExternalLock ); + + public: + // XInterface + DECLARE_XINTERFACE( ) + DECLARE_XTYPEPROVIDER( ) + + // XAccessibleComponent - default implementations + virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException); + }; + + //===================================================================== + //= OAccessibleExtendedComponentHelper + //===================================================================== + + typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessibleExtendedComponent + > OAccessibleExtendedComponentHelper_Base; + + /** a helper class for implementing an AccessibleContext which at the same time + supports an XAccessibleExtendedComponent interface. + */ + class COMPHELPER_DLLPUBLIC OAccessibleExtendedComponentHelper + :public OCommonAccessibleComponent + ,public OAccessibleExtendedComponentHelper_Base + { + protected: + OAccessibleExtendedComponentHelper( ); + /// see the respective base class ctor for an extensive comment on this, please + OAccessibleExtendedComponentHelper( IMutex* _pExternalLock ); + + public: + // XInterface + DECLARE_XINTERFACE( ) + DECLARE_XTYPEPROVIDER( ) + + // XAccessibleComponent - default implementations + virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_ACCESSIBLE_COMPONENT_HELPER_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessiblecontexthelper.hxx b/include/comphelper/accessiblecontexthelper.hxx new file mode 100644 index 000000000000..e6c5c10ab20f --- /dev/null +++ b/include/comphelper/accessiblecontexthelper.hxx @@ -0,0 +1,345 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_CONTEXT_HELPER_HXX +#define COMPHELPER_ACCESSIBLE_CONTEXT_HELPER_HXX + +#include <cppuhelper/compbase2.hxx> +#include <com/sun/star/accessibility/XAccessibleContext.hpp> +#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <comphelper/broadcasthelper.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= IMutex + //===================================================================== + + // This whole thingie here (own mutex classes and such) is a HACK. I hate the SolarMutex. + // See below for more explanations .... + + /** abstract interface for implementing a mutex + */ + class COMPHELPER_DLLPUBLIC IMutex + { + public: + virtual ~IMutex(); + virtual void acquire() = 0; + virtual void release() = 0; + }; + + //===================================================================== + //= OMutexGuard + //===================================================================== + + class OMutexGuard + { + IMutex* m_pMutex; + public: + inline OMutexGuard( IMutex* _pMutex ) + :m_pMutex( _pMutex ) + { + if ( m_pMutex ) + m_pMutex->acquire(); + } + + inline ~OMutexGuard( ) + { + if ( m_pMutex ) + m_pMutex->release(); + } + }; + + //===================================================================== + //= OAccessibleContextHelper + //===================================================================== + + class OContextHelper_Impl; + typedef ::cppu::WeakAggComponentImplHelper2 < ::com::sun::star::accessibility::XAccessibleContext, + ::com::sun::star::accessibility::XAccessibleEventBroadcaster + > OAccessibleContextHelper_Base; + + /** helper class for implementing an AccessibleContext + */ + class COMPHELPER_DLLPUBLIC OAccessibleContextHelper + :public ::comphelper::OBaseMutex + ,public OAccessibleContextHelper_Base + { + private: + OContextHelper_Impl* m_pImpl; + + protected: + OAccessibleContextHelper( ); + ~OAccessibleContextHelper( ); + + /** ctor + + <p>If you need additional object safety for your class, and want to ensure that your own + mutex is locked before the mutex this class provides is, than use this ctor.</p> + + <p>Beware that this is a hack. Unfortunately, OpenOffice.org has two different mutex hierarchies, + which are not compatible. In addition, wide parts of the code (especially VCL) is not thread-safe, + but instead relies on a <em>single global mutex</em>. As a consequence, components using + directly or indirectly such code need to care for this global mutex. Yes, this is as ugly as + anything.</p> + + <p>Note that the external lock is used as additional lock, not as the only one. The own mutex of the + instance is used for internal actions, and every action which potentially involves external code + (for instance every call to a virtual method overridden by derivees) is <em>additionally</em> and + <em>first</em> guarded by with the external lock.</p> + + <p>Beware of the lifetime of the lock - you must ensure that the lock exists at least as long as + the context does. A good approach to implement the lock may be to derive you own context + not only from OAccessibleContextHelper, but also from IMutex.</p> + + <p>One more note. This lock is definitely not used once the dtor is reached. Means whatever + the dtor implementation does, it does <em>not</em> guard the external lock. See this as a contract. + <br/>You should ensure the same thing for own derivees which do not supply the lock themself, + but get them from yet another derivee.</p> + @see forgetExternalLock + */ + OAccessibleContextHelper( IMutex* _pExternalLock ); + + /** late construction + @param _rxAccessible + the Accessible object which created this context. + <p>If your derived implementation implements the XAccessible (and does not follow the proposed + separation of XAccessible from XAccessibleContext), you may pass <code>this</code> here.</p> + + <p>The object is hold weak, so it's life time is not affected.</p> + + <p>The object is needed for performance reasons: for <method>getAccessibleIndexInParent</method>, + all children (which are XAccessible's theirself) of our parent have to be asked. If we know our + XAccessible, we can compare it with all the children, instead of asking all children for their + context and comparing this context with ourself.</p> + */ + void lateInit( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxAccessible ); + + /** retrieves the creator previously set with <method>lateInit</method> + */ + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + getAccessibleCreator( ) const; + + /** forgets the reference to the external lock, if present. + + <p>This means any further locking will not be guard the external lock anymore, never.</p> + + <p>To be used in derived classes which do not supply the external lock themself, but instead get + them passed from own derivees (or clients).</p> + */ + void forgetExternalLock(); + + public: + // XAccessibleEventBroadcaster + virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // XAccessibleContext - still waiting to be overwritten + virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) = 0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException) = 0; + + // XAccessibleContext - default implementations + /** default implementation for retrieving the index of this object within the parent + <p>This basic implementation here returns the index <code>i</code> of the child for which + <code><parent>.getAccessibleChild( i )</code> equals our creator.</p> + */ + virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException); + /** default implementation for retrieving the locale + <p>This basic implementation returns the locale of the parent context, + as retrieved via getAccessibleParent()->getAccessibleContext.</p> + */ + virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException); + + public: + // helper struct for granting selective access rights + struct OAccessControl + { + friend class OContextEntryGuard; + friend class OContextHelper_Impl; + friend class OExternalLockGuard; + private: + OAccessControl() { } + }; + + // ensures that the object is alive + inline void ensureAlive( const OAccessControl& ) const SAL_THROW( ( ::com::sun::star::lang::DisposedException ) ); + inline IMutex* getExternalLock( const OAccessControl& ); + inline ::osl::Mutex& GetMutex( const OAccessControl& ); + + protected: + // OComponentHelper + virtual void SAL_CALL disposing(); + + protected: + // helper + /** notifies all AccessibleEventListeners of a certain event + + @precond not too be called with our mutex locked + @param _nEventId + the id of the even. See AccessibleEventType + @param _rOldValue + the old value to be notified + @param _rNewValue + the new value to be notified + */ + virtual void SAL_CALL NotifyAccessibleEvent( + const sal_Int16 _nEventId, + const ::com::sun::star::uno::Any& _rOldValue, + const ::com::sun::star::uno::Any& _rNewValue + ); + + // life time control + /// checks whether the object is alive (returns <TRUE/> then) or disposed + sal_Bool isAlive() const; + /// checks for beeing alive. If the object is already disposed (i.e. not alive), an exception is thrown. + void ensureAlive() const SAL_THROW( ( ::com::sun::star::lang::DisposedException ) ); + + /** ensures that the object is disposed. + @precond + to be called from within the destructor of your derived class only! + */ + void ensureDisposed( ); + + /** shortcut for retrieving the context of the parent (returned by getAccessibleParent) + */ + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + implGetParentContext() SAL_THROW( ( ::com::sun::star::uno::RuntimeException ) ); + + // access to the base class' broadcast helper/mutex + ::cppu::OBroadcastHelper& GetBroadcastHelper() { return rBHelper; } + const ::cppu::OBroadcastHelper& GetBroadcastHelper() const { return rBHelper; } + ::osl::Mutex& GetMutex() { return m_aMutex; } + IMutex* getExternalLock( ); + }; + + //--------------------------------------------------------------------- + inline void OAccessibleContextHelper::ensureAlive( const OAccessControl& ) const SAL_THROW( ( ::com::sun::star::lang::DisposedException ) ) + { + ensureAlive(); + } + + //--------------------------------------------------------------------- + inline IMutex* OAccessibleContextHelper::getExternalLock( const OAccessControl& ) + { + return getExternalLock(); + } + + //--------------------------------------------------------------------- + inline ::osl::Mutex& OAccessibleContextHelper::GetMutex( const OAccessControl& ) + { + return GetMutex(); + } + + //===================================================================== + //= OContextEntryGuard + //===================================================================== + typedef ::osl::ClearableMutexGuard OContextEntryGuard_Base; + /** helper class for guarding the entry into OAccessibleContextHelper methods. + + <p>The class has two responsibilities: + <ul><li>it locks the mutex of an OAccessibleContextHelper instance, as long as the guard lives</li> + <li>it checks if an given OAccessibleContextHelper instance is alive, else an exception is thrown + our of the constructor of the guard</li> + </ul> + <br/> + This makes it your first choice (hopefully :) for guarding any interface method implementations of + you derived class. + </p> + */ + class OContextEntryGuard : public OContextEntryGuard_Base + { + public: + /** constructs the guard + + <p>The given context (it's mutex, respectively) is locked, and an exception is thrown if the context + is not alive anymore. In the latter case, of course, the mutex is freed, again.</p> + + @param _pContext + the context which shall be guarded + @precond <arg>_pContext</arg> != NULL + */ + inline OContextEntryGuard( OAccessibleContextHelper* _pContext ); + + /** destructs the guard. + <p>The context (it's mutex, respectively) is unlocked.</p> + */ + inline ~OContextEntryGuard(); + }; + + //..................................................................... + inline OContextEntryGuard::OContextEntryGuard( OAccessibleContextHelper* _pContext ) + :OContextEntryGuard_Base( _pContext->GetMutex( OAccessibleContextHelper::OAccessControl() ) ) + { + _pContext->ensureAlive( OAccessibleContextHelper::OAccessControl() ); + } + + //..................................................................... + inline OContextEntryGuard::~OContextEntryGuard() + { + } + + //===================================================================== + //= OExternalLockGuard + //===================================================================== + class OExternalLockGuard + :public OMutexGuard + ,public OContextEntryGuard + { + public: + inline OExternalLockGuard( OAccessibleContextHelper* _pContext ); + inline ~OExternalLockGuard( ); + }; + + //..................................................................... + inline OExternalLockGuard::OExternalLockGuard( OAccessibleContextHelper* _pContext ) + :OMutexGuard( _pContext->getExternalLock( OAccessibleContextHelper::OAccessControl() ) ) + ,OContextEntryGuard( _pContext ) + { + // #102438# + // Only lock the external mutex, + // release the ::osl::Mutex of the OAccessibleContextHelper instance. + // If you call into another UNO object with locked ::osl::Mutex, + // this may lead to dead locks. + clear(); + } + + //..................................................................... + inline OExternalLockGuard::~OExternalLockGuard( ) + { + } + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_ACCESSIBLE_CONTEXT_HELPER_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessibleeventnotifier.hxx b/include/comphelper/accessibleeventnotifier.hxx new file mode 100644 index 000000000000..f0a745baa5a8 --- /dev/null +++ b/include/comphelper/accessibleeventnotifier.hxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER +#define COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER + +#include <com/sun/star/accessibility/AccessibleEventObject.hpp> +#include <com/sun/star/accessibility/XAccessibleEventListener.hpp> +#include <osl/thread.hxx> +#include <osl/conditn.hxx> +#include <cppuhelper/interfacecontainer.h> +#include "comphelper/comphelperdllapi.h" + +#include <map> +#include <list> + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= AccessibleEventNotifier + //===================================================================== + class COMPHELPER_DLLPUBLIC AccessibleEventNotifier + { + // typedefs + public: + typedef sal_uInt32 TClientId; + + typedef ::std::pair< TClientId, ::com::sun::star::accessibility::AccessibleEventObject > + ClientEvent; + + typedef ::cppu::OInterfaceContainerHelper EventListeners; + typedef ::std::map< TClientId, EventListeners*, ::std::less< TClientId > > ClientMap; + + protected: + AccessibleEventNotifier( ); // never implemented + ~AccessibleEventNotifier( ); // never implemented + + private: + COMPHELPER_DLLPRIVATE AccessibleEventNotifier( const AccessibleEventNotifier& ); // never implemented! + COMPHELPER_DLLPRIVATE AccessibleEventNotifier& operator=( const AccessibleEventNotifier& ); // never implemented! + + public: + /** registers a client of this class, means a broadcaster of AccessibleEvents + + <p>No precaution is taken to care for disposal of this component. When the component + dies, it <b>must</b> call <member>revokeClient</member> or <member>revokeClientNotifyDisposing</member> + explicitly itself.</p> + */ + static TClientId registerClient( ); + + /** revokes a broadcaster of AccessibleEvents + + <p>Note that no disposing event is fired when you use this method, the client is simply revoked. + You can for instance revoke a client if the last listener for it is revoked, but the client + itself is not disposed.<br/> + When the client is disposed, you should prefer <member>revokeClientNotifyDisposing</member></p> + + <p>Any possibly pending events for this client are removed from the queue.</p> + + @seealso revokeClientNotifyDisposing + */ + static void revokeClient( const TClientId _nClient ); + + /** revokes a client, with additionally notifying a disposing event to all listeners registered for + this client + + <p>Any other possibly pending events for this client are removed from the queue</p> + + @param _nClient + the id of the client which should be revoked + @param _rxEventSource + the source to be notified together with the <member scope="com.sun.star.lang">XComponent::disposing</member> + call. + */ + static void revokeClientNotifyDisposing( + const TClientId _nClient, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxEventSource + ) SAL_THROW( ( ) ); + + /** registers a listener for the given client + + @param _nClient + the id of the client for which a listener should be registered + @return + the number of event listeners currently registered for this client + */ + static sal_Int32 addEventListener( + const TClientId _nClient, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& _rxListener + ) SAL_THROW( ( ) ); + + /** revokes a listener for the given client + + @param _nClient + the id of the client for which a listener should be revoked + @return + the number of event listeners currently registered for this client + */ + static sal_Int32 removeEventListener( + const TClientId _nClient, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& _rxListener + ) SAL_THROW( ( ) ); + + /** adds an event, which is to be braodcasted, to the queue + + @param _nClient + the id of the client which needs to broadcast the event + */ + static void addEvent( + const TClientId _nClient, + const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent + ) SAL_THROW( ( ) ); + + private: + /// generates a new client id + COMPHELPER_DLLPRIVATE static TClientId generateId(); + + /** looks up a client in our client map, asserts if it cannot find it or no event thread is present + + @precond + to be called with our mutex locked + + @param _nClient + the id of the client to loopup + @param _rPos + out-parameter for the position of the client in the client map + + @return + <TRUE/> if and only if the client could be found and <arg>_rPos</arg> has been filled with + it's position + */ + COMPHELPER_DLLPRIVATE static sal_Bool implLookupClient( const TClientId _nClient, ClientMap::iterator& _rPos ); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessiblekeybindinghelper.hxx b/include/comphelper/accessiblekeybindinghelper.hxx new file mode 100644 index 000000000000..4849b124cf87 --- /dev/null +++ b/include/comphelper/accessiblekeybindinghelper.hxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_KEYBINDING_HELPER_HXX +#define COMPHELPER_ACCESSIBLE_KEYBINDING_HELPER_HXX + +#include <com/sun/star/accessibility/XAccessibleKeyBinding.hpp> +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> + +#include <vector> + +#include "comphelper/comphelperdllapi.h" + +//.............................................................................. +namespace comphelper +{ +//.............................................................................. + + //============================================================================== + // OAccessibleKeyBindingHelper + //============================================================================== + + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::accessibility::XAccessibleKeyBinding + > OAccessibleKeyBindingHelper_Base; + + /** a helper class for implementing an accessible keybinding + */ + class COMPHELPER_DLLPUBLIC OAccessibleKeyBindingHelper : public OAccessibleKeyBindingHelper_Base + { + private: + typedef ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::awt::KeyStroke > > KeyBindings; + + KeyBindings m_aKeyBindings; + + protected: + ::osl::Mutex m_aMutex; + + virtual ~OAccessibleKeyBindingHelper(); + + public: + OAccessibleKeyBindingHelper(); + OAccessibleKeyBindingHelper( const OAccessibleKeyBindingHelper& rHelper ); + + void AddKeyBinding( const ::com::sun::star::uno::Sequence< ::com::sun::star::awt::KeyStroke >& rKeyBinding ) throw (::com::sun::star::uno::RuntimeException); + void AddKeyBinding( const ::com::sun::star::awt::KeyStroke& rKeyStroke ) throw (::com::sun::star::uno::RuntimeException); + + // XAccessibleKeyBinding + virtual sal_Int32 SAL_CALL getAccessibleKeyBindingCount() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::awt::KeyStroke > SAL_CALL getAccessibleKeyBinding( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + }; + +//.............................................................................. +} // namespace comphelper +//.............................................................................. + +#endif // COMPHELPER_ACCESSIBLE_KEYBINDING_HELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessibleselectionhelper.hxx b/include/comphelper/accessibleselectionhelper.hxx new file mode 100644 index 000000000000..e1bb5dd5f1ef --- /dev/null +++ b/include/comphelper/accessibleselectionhelper.hxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_SELECTION_HELPER_HXX +#define COMPHELPER_ACCESSIBLE_SELECTION_HELPER_HXX + +#include <comphelper/uno3.hxx> +#include <comphelper/accessiblecomponenthelper.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/accessibility/XAccessibleSelection.hpp> +#include "comphelper/comphelperdllapi.h" + +#define ACCESSIBLE_SELECTION_CHILD_ALL ((sal_Int32)-1) +#define ACCESSIBLE_SELECTION_CHILD_SELF ((sal_Int32)-2) + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= OCommonAccessibleSelection + //===================================================================== + /** base class encapsulating common functionality for the helper classes implementing + the XAccessibleSelection + */ + class COMPHELPER_DLLPUBLIC OCommonAccessibleSelection + { + protected: + + OCommonAccessibleSelection(); + + ~OCommonAccessibleSelection(); + + protected: + + // access to context - still waiting to be overwritten + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + implGetAccessibleContext() + throw ( ::com::sun::star::uno::RuntimeException ) = 0; + + // return if the specified child is visible => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx) + virtual sal_Bool + implIsSelected( sal_Int32 nAccessibleChildIndex ) + throw (::com::sun::star::uno::RuntimeException) = 0; + + // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx) + virtual void + implSelect( sal_Int32 nAccessibleChildIndex, sal_Bool bSelect ) + throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) = 0; + + protected: + + /** non-virtual versions of the methods which can be implemented using <method>implIsSelected</method> and <method>implSelect</method> + */ + void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException); + void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException); + sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + }; + + //===================================================================== + //= OAccessibleSelectionHelper + //===================================================================== + + typedef ::cppu::ImplHelper1< ::com::sun::star::accessibility::XAccessibleSelection > OAccessibleSelectionHelper_Base; + + /** a helper class for implementing an AccessibleSelection which at the same time + supports an XAccessibleSelection interface. + */ + class COMPHELPER_DLLPUBLIC OAccessibleSelectionHelper : public OAccessibleComponentHelper, + public OCommonAccessibleSelection, + public OAccessibleSelectionHelper_Base + { + protected: + + /// see the respective base class ctor for an extensive comment on this, please + OAccessibleSelectionHelper( IMutex* _pExternalLock ); + + // return ourself here by default + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > implGetAccessibleContext() throw ( ::com::sun::star::uno::RuntimeException ); + + public: + + // XInterface + DECLARE_XINTERFACE( ) + DECLARE_XTYPEPROVIDER( ) + + // XAccessibleSelection - default implementations + virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_ACCESSIBLE_SELECTION_HELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessibletexthelper.hxx b/include/comphelper/accessibletexthelper.hxx new file mode 100644 index 000000000000..ea3f505ee7fe --- /dev/null +++ b/include/comphelper/accessibletexthelper.hxx @@ -0,0 +1,178 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX +#define COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX + +#include <com/sun/star/accessibility/XAccessibleText.hpp> +#include <com/sun/star/accessibility/TextSegment.hpp> +#include <com/sun/star/i18n/XBreakIterator.hpp> +#include <com/sun/star/i18n/XCharacterClassification.hpp> +#include <comphelper/accessiblecomponenthelper.hxx> +#include <cppuhelper/implbase1.hxx> +#include "comphelper/comphelperdllapi.h" + + +//.............................................................................. +namespace comphelper +{ +//.............................................................................. + + //============================================================================== + // OCommonAccessibleText + //============================================================================== + /** base class encapsulating common functionality for the helper classes implementing + the XAccessibleText + */ + class COMPHELPER_DLLPUBLIC OCommonAccessibleText + { + private: + ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > m_xBreakIter; + ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XCharacterClassification > m_xCharClass; + + protected: + OCommonAccessibleText(); + virtual ~OCommonAccessibleText(); + + ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > implGetBreakIterator(); + ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XCharacterClassification > implGetCharacterClassification(); + sal_Bool implIsValidBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nLength ); + virtual sal_Bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength ); + virtual sal_Bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength ); + virtual OUString implGetText() = 0; + virtual ::com::sun::star::lang::Locale implGetLocale() = 0; + virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0; + virtual void implGetGlyphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex ); + virtual sal_Bool implGetWordBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex ); + virtual void implGetSentenceBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex ); + virtual void implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex ); + virtual void implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex ); + + /** non-virtual versions of the methods + */ + sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException); + OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException); + sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException); + sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException); + OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException); + OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + public: + + /** Helper method, that detects the difference between + two strings and returns the deleted selection and + the inserted selection if available. + + @returns true if there are differences between the + two strings and false if both are equal + + @see ::com::sun::star::accessibility::AccessibleEventId + ::com::sun::star::accessibility::TextSegment + */ + static bool implInitTextChangedEvent( + const OUString& rOldString, + const OUString& rNewString, + /*out*/ ::com::sun::star::uno::Any& rDeleted, + /*out*/ ::com::sun::star::uno::Any& rInserted); // throw() + }; + + + //============================================================================== + // OAccessibleTextHelper + //============================================================================== + + typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessibleText + > OAccessibleTextHelper_Base; + + /** a helper class for implementing an AccessibleExtendedComponent which at the same time + supports an XAccessibleText interface + */ + class COMPHELPER_DLLPUBLIC OAccessibleTextHelper : public OAccessibleExtendedComponentHelper, + public OCommonAccessibleText, + public OAccessibleTextHelper_Base + { + protected: + // see the respective base class ctor for an extensive comment on this, please + OAccessibleTextHelper( IMutex* _pExternalLock ); + + public: + // XInterface + DECLARE_XINTERFACE( ) + + // XTypeProvider + DECLARE_XTYPEPROVIDER( ) + + // XAccessibleText + virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + }; + +//.............................................................................. +} // namespace comphelper +//.............................................................................. + +#endif // COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX + + +// ----------------------------------------------------------------------------- +// +// OAccessibleTextHelper is a helper class for implementing the +// XAccessibleText interface. +// +// The following methods have a default implementation: +// +// getCharacter +// getCharacterCount +// getSelectedText +// getSelectionStart +// getSelectionEnd +// getText +// getTextRange +// getTextAtIndex +// getTextBeforeIndex +// getTextBehindIndex +// +// The following methods must be overriden by derived classes: +// +// implGetText +// implGetLocale +// implGetSelection +// getCaretPosition +// setCaretPosition +// getCharacterAttributes +// getCharacterBounds +// getIndexAtPoint +// setSelection +// copyText +// +// ----------------------------------------------------------------------------- + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accessiblewrapper.hxx b/include/comphelper/accessiblewrapper.hxx new file mode 100644 index 000000000000..fbd65d638899 --- /dev/null +++ b/include/comphelper/accessiblewrapper.hxx @@ -0,0 +1,410 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCESSIBLE_WRAPPER_HXX +#define COMPHELPER_ACCESSIBLE_WRAPPER_HXX + +#include <comphelper/proxyaggregation.hxx> +#include <com/sun/star/accessibility/XAccessible.hpp> +#include <com/sun/star/accessibility/XAccessibleContext.hpp> +#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> +#include <com/sun/star/accessibility/XAccessibleEventListener.hpp> +#include <cppuhelper/compbase3.hxx> +#include <cppuhelper/compbase2.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/sequence.hxx> +#include <comphelper/uno3.hxx> +#include <cppuhelper/interfacecontainer.hxx> +#include <comphelper/broadcasthelper.hxx> +#include <comphelper/accessibleeventnotifier.hxx> +#include <comphelper/stl_types.hxx> +#include "comphelper/comphelperdllapi.h" + +//............................................................................. +namespace comphelper +{ +//............................................................................. + + //========================================================================= + //= OAccessibleWrapper + //========================================================================= + + class OAccessibleContextWrapper; + class OWrappedAccessibleChildrenManager; + + struct OAccessibleWrapper_Base : + public ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessible > + { + protected: + ~OAccessibleWrapper_Base() {} + }; + + /** a class which aggregates a proxy for an XAccessible, and wrapping the context returned by this + XAccessible. + */ + class COMPHELPER_DLLPUBLIC OAccessibleWrapper:public OAccessibleWrapper_Base + ,public OComponentProxyAggregation + + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + m_xParentAccessible; + ::com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessibleContext > + m_aContext; + + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + m_xInnerAccessible; + + public: + /** ctor + @param _rxContext + a service factory + + @param _rxInnerAccessible + the object to wrap + + @param _rxParentAccessible + The XAccessible which is our parent + */ + OAccessibleWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxInnerAccessible, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible + ); + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + + // returns the context without creating it + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + getContextNoCreate( ) const; + + protected: + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL + getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException); + + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + getParent() const { return m_xParentAccessible; } + + // own overridables + virtual OAccessibleContextWrapper* createAccessibleContext( + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerContext + ); + + protected: + ~OAccessibleWrapper( ); + + private: + COMPHELPER_DLLPRIVATE OAccessibleWrapper( ); // never implemented + COMPHELPER_DLLPRIVATE OAccessibleWrapper( const OAccessibleWrapper& ); // never implemented + COMPHELPER_DLLPRIVATE OAccessibleWrapper& operator=( const OAccessibleWrapper& ); // never implemented + }; + + //========================================================================= + //= OAccessibleContextWrapperHelper + //========================================================================= + + typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessibleEventListener + > OAccessibleContextWrapperHelper_Base; + + /** Helper for wrapping an XAccessibleContext by aggregating a proxy for it. + + <p>This class does not have own ref counting. In addition, it does not implement + the XAccesibleContext interface, but provides all the methods from this interface + which must be implemented using the inner context (such as getAccessibleChild*).</p> + + <p>Children of the aggregated XAccessibleContext are wrapped, too.</p> + + <p>AccessibleEvents fired by the inner context are multiplexed, especially, any references to + children in such events are translated. This means that even in such events, no un-wrapped object + will ever leave this class - if the aggregated context notifies an child event, the child passed + to the event is wrapped</p> + + @seealso OAccessibleContextWrapper + */ + class COMPHELPER_DLLPUBLIC OAccessibleContextWrapperHelper + :private OComponentProxyAggregationHelper + ,public OAccessibleContextWrapperHelper_Base + { + protected: + /// the context we're wrapping (properly typed, in opposite to OComponentProxyAggregationHelper::m_xInner) + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + m_xInnerContext; + /// the XAccessible which created this context + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + m_xOwningAccessible; + /// the XAccessible which is to be returned in getAccessibleParent + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + m_xParentAccessible; + + OWrappedAccessibleChildrenManager* m_pChildMapper; // for mapping children from our inner context to our callers + + protected: + /** ctor + + @param _rxContext + a service factory + + @param _rxInnerAccessibleContext + the object to wrap + + @param _rxOwningAccessible + The XAccessible which created this object. This is necessary because children + of our wrapped context meed to be wrapped, too, and if they're asked for a parent, + they of course should return the proper parent<br/> + The object will be held with a hard reference + + @param _rxParentAccessible + The XAccessible to return in the getAccessibleParent call + */ + OAccessibleContextWrapperHelper( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + ::cppu::OBroadcastHelper& _rBHelper, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerAccessibleContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxOwningAccessible, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible + ); + + /// to be called from within your ctor - does the aggregation of a proxy for m_xInnerContext + void aggregateProxy( + oslInterlockedCount& _rRefCount, + ::cppu::OWeakObject& _rDelegator + ); + + protected: + // XInterface + ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException); + + // XTypeProvider + DECLARE_XTYPEPROVIDER( ) + + // XAccessibleContext + virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException); + + // XAccessibleEventListener + virtual void SAL_CALL notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent/OComponentProxyAggregationHelper + virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); + + // own overridables + /** notify an accessible event which has been translated (if necessary) + + <p>Usually, you derive your clas from both OAccessibleContextWrapperHelper and XAccessibleEventBroadcaster, + and simply call all your XAccessibleEventListener with the given event.</p> + + <p>The mutex of the BroadcastHelper passed to the instance's ctor is <em>not</em> locked when calling + into this method</p> + */ + virtual void notifyTranslatedEvent( const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent ) throw (::com::sun::star::uno::RuntimeException) = 0; + + protected: + ~OAccessibleContextWrapperHelper( ); + + OAccessibleContextWrapperHelper( ); // never implemented + OAccessibleContextWrapperHelper( const OAccessibleContextWrapperHelper& ); // never implemented + OAccessibleContextWrapperHelper& operator=( const OAccessibleContextWrapperHelper& ); // never implemented + }; + + //========================================================================= + //= OAccessibleContextWrapper + //========================================================================= + typedef ::cppu::PartialWeakComponentImplHelper2< ::com::sun::star::accessibility::XAccessibleEventBroadcaster + , ::com::sun::star::accessibility::XAccessibleContext + > OAccessibleContextWrapper_CBase; + + class COMPHELPER_DLLPUBLIC OAccessibleContextWrapper + :public OBaseMutex + ,public OAccessibleContextWrapper_CBase + ,public OAccessibleContextWrapperHelper + { + private: + ::comphelper::AccessibleEventNotifier::TClientId m_nNotifierClient; // for notifying AccessibleEvents + + public: + /** ctor + + @param _rxContext + a service factory + + @param _rxInnerAccessibleContext + the object to wrap + + @param _rxOwningAccessible + The XAccessible which created this object. This is necessary because children + of our wrapped context meed to be wrapped, too, and if they're asked for a parent, + they of course should return the proper parent<br/> + The object will be held with a hard reference + + @param _rxParentAccessible + The XAccessible to return in the getAccessibleParent call + */ + OAccessibleContextWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerAccessibleContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxOwningAccessible, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible + ); + + // XInterface + DECLARE_XINTERFACE( ) + // XTypeProvider + DECLARE_XTYPEPROVIDER( ) + + // XAccessibleContext + virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException); + + // XAccessibleEventBroadcaster + virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // OAccessibleContextWrapper + virtual void notifyTranslatedEvent( const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException) + { WeakComponentImplHelperBase::addEventListener(xListener); } + virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException) + { WeakComponentImplHelperBase::removeEventListener(xListener); } + + // OComponentHelper + using OAccessibleContextWrapperHelper::disposing; + virtual void SAL_CALL disposing() throw (::com::sun::star::uno::RuntimeException); + + protected: + virtual ~OAccessibleContextWrapper(); + + private: + COMPHELPER_DLLPRIVATE OAccessibleContextWrapper(); // never implemented + COMPHELPER_DLLPRIVATE OAccessibleContextWrapper( const OAccessibleContextWrapper& ); // never implemented + COMPHELPER_DLLPRIVATE OAccessibleContextWrapper& operator=( const OAccessibleContextWrapper& ); // never implemented + }; + + //========================================================================= + //= OWrappedAccessibleChildrenManager + //========================================================================= + + typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + , ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + , OInterfaceCompare< ::com::sun::star::accessibility::XAccessible > + > AccessibleMap; + // TODO: think about if we should hold these objects weak + + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener + > OWrappedAccessibleChildrenManager_Base; + /** manages wrapping XAccessible's to XAccessible's + */ + class COMPHELPER_DLLPUBLIC OWrappedAccessibleChildrenManager : public OWrappedAccessibleChildrenManager_Base + { + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + ::com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > + m_aOwningAccessible; // the XAccessible which belongs to the XAccessibleContext which we work for + AccessibleMap m_aChildrenMap; // for caching children + sal_Bool m_bTransientChildren; // are we prohibited to cache our children? + + public: + /// ctor + OWrappedAccessibleChildrenManager( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext + ); + + /** specifies if the children are to be consideren transient (i.e.: not cached) + <p>to be called only once per lifetime</p> + */ + void setTransientChildren( sal_Bool _bSet = sal_True ); + + /** sets the XAccessible which belongs to the XAccessibleContext which we work for + <p>to be called only once per lifetime</p> + */ + void setOwningAccessible( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxAcc ); + + /// retrieves a wrapper for the given accessible + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + getAccessibleWrapperFor( + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxKey, + sal_Bool _bCreate = sal_True + ); + + /// erases the given key from the map (if it is present there) + void removeFromCache( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxKey ); + + /// invalidates (i.e. empties) the map + void invalidateAll( ); + + /** disposes (i.e. cleares) the manager + + <p>Note that the XAccessibleContext's of the mapped XAccessible objects are disposed, too.</p> + */ + void dispose(); + + /** handles a notification as got from the parent of the children we're managing + <p>This applies only to the notifications which have a direct impact on our map.</p> + */ + void handleChildNotification( const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent ); + + /** translates events as got from the parent of the children we're managing + <p>This applies only to the notifications which deal with child objects which we manage.</p> + */ + void translateAccessibleEvent( + const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent, + ::com::sun::star::accessibility::AccessibleEventObject& _rTranslatedEvent + ); + + protected: + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + protected: + void implTranslateChildEventValue( const ::com::sun::star::uno::Any& _rInValue, ::com::sun::star::uno::Any& _rOutValue ); + + protected: + ~OWrappedAccessibleChildrenManager( ); + + private: + COMPHELPER_DLLPRIVATE OWrappedAccessibleChildrenManager( ); // never implemented + COMPHELPER_DLLPRIVATE OWrappedAccessibleChildrenManager( const OWrappedAccessibleChildrenManager& ); // never implemented + COMPHELPER_DLLPRIVATE OWrappedAccessibleChildrenManager& operator=( const OWrappedAccessibleChildrenManager& ); // never implemented + }; + +//............................................................................. +} // namespace accessibility +//............................................................................. + +#endif // COMPHELPER_ACCESSIBLE_WRAPPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/accimplaccess.hxx b/include/comphelper/accimplaccess.hxx new file mode 100644 index 000000000000..3407c5a7b8b4 --- /dev/null +++ b/include/comphelper/accimplaccess.hxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ACCIMPLACCESS_HXX +#define COMPHELPER_ACCIMPLACCESS_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include "comphelper/comphelperdllapi.h" + +// forward declaration +namespace com { namespace sun { namespace star { namespace accessibility { + class XAccessible; + class XAccessibleContext; +}}}} + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= OAccessibleImplementationAccess + //===================================================================== + typedef ::cppu::ImplHelper1 < ::com::sun::star::lang::XUnoTunnel + > OAccImpl_Base; + struct OAccImpl_Impl; + + /** This is a helper class which allows accessing several aspects of the implementation + of an AccessibleContext. + + <p>For instance, when you want to implement a context which can be re-parented, you: + <ul><li>derive your class from <type>OAccessibleImplementationAccess</type></li> + <li>use <code>setAccessibleParent( <em>component</em>, <em>new_parent</em> )</code> + </ul> + </p> + + <p>Another aspect which can be controlled from the outside are states. If you have a class which + has only partial control over it's states, you may consider deriving from OAccessibleImplementationAccess.<br/> + For instance, say you have an implementation (say component A) which is <em>unable</em> to know or to + determine if the represented object is selected, but another component (say B) which uses A (and integrates + it into a tree of accessibility components) is.<br/> + In this case, if A is derived from OAccessibleImplementationAccess, B can manipulate this + foreign-controlled state flag "SELECTED" by using the static helper methods on this class.</p> + + <p>Please note that the support for foreign controlled states is rather restrictive: You can't have states + which <em>may be</em> controlled by a foreign instances. This is implied by the fact that a derived + class can ask for states which are <em>set</em> only, not for the ones which are <em>reset</em> currently. + </p> + */ + class COMPHELPER_DLLPUBLIC OAccessibleImplementationAccess : public OAccImpl_Base + { + private: + OAccImpl_Impl* m_pImpl; + + protected: + /// retrieves the parent previously set via <method>setAccessibleParent</method> + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + implGetForeignControlledParent( ) const; + + /** retrieves the set of currently set states which are controlled by a foreign instance + @return + a bit mask, where a set bit 2^n means that the AccessibleStateType n has been set + */ + sal_Int64 implGetForeignControlledStates( ) const; + + /// sets the accessible parent component + virtual void setAccessibleParent( + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxAccParent ); + + /// sets or resets a bit of the foreign controlled states + virtual void setStateBit( const sal_Int16 _nState, const sal_Bool _bSet ); + + protected: + OAccessibleImplementationAccess( ); + virtual ~OAccessibleImplementationAccess( ); + + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rIdentifier ) throw (::com::sun::star::uno::RuntimeException); + + public: + /** tries to access the implementation of an OAccessibleImplementationAccess derivee which is known as + interface only. + + @param _rxComponent + is the component which should be examined. + @return + the pointer to the implementation, if successful. The only known error condition so far + is an invalid context (which means it is <NULL/>, or the implementation is not derived + from <type>OAccessibleImplementationAccess</type>, or retrieving the implementation failed). + */ + static OAccessibleImplementationAccess* getImplementation( + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxComponent + ); + + + /** sets the parent for a derived implementation + + @param _rxComponent + is the component which's new parent should be set + @param _rxNewParent + is the new parent of the component + @return + <TRUE/> in case of success, <FALSE/> otherwise. For error condition please look at + <method>getImplementation</method>. + */ + static sal_Bool setAccessibleParent( + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxComponent, + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxNewParent + ); + + + private: + COMPHELPER_DLLPRIVATE static const ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + + +#endif // COMPHELPER_ACCIMPLACCESS_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/anycompare.hxx b/include/comphelper/anycompare.hxx new file mode 100644 index 000000000000..fb17b7ca67ec --- /dev/null +++ b/include/comphelper/anycompare.hxx @@ -0,0 +1,219 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ANYCOMPARE_HXX +#define COMPHELPER_ANYCOMPARE_HXX + +#include "comphelper/comphelperdllapi.h" + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/i18n/XCollator.hpp> + +#include <comphelper/extract.hxx> + +#include <functional> +#include <memory> + +//...................................................................................................................... +namespace comphelper +{ +//...................................................................................................................... + + //================================================================================================================== + //= IKeyPredicateLess + //================================================================================================================== + class SAL_NO_VTABLE IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const = 0; + virtual ~IKeyPredicateLess() {} + }; + + //================================================================================================================== + //= LessPredicateAdapter + //================================================================================================================== + struct LessPredicateAdapter : public ::std::binary_function< ::com::sun::star::uno::Any, ::com::sun::star::uno::Any, bool > + { + LessPredicateAdapter( const IKeyPredicateLess& _predicate ) + :m_predicate( _predicate ) + { + } + + bool operator()( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + return m_predicate.isLess( _lhs, _rhs ); + } + + private: + IKeyPredicateLess const & m_predicate; + + private: + LessPredicateAdapter(); // never implemented + }; + + //================================================================================================================== + //= ScalarPredicateLess + //================================================================================================================== + template< typename SCALAR > + class ScalarPredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + SCALAR lhs(0), rhs(0); + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + return lhs < rhs; + } + }; + + //================================================================================================================== + //= StringPredicateLess + //================================================================================================================== + class StringPredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + OUString lhs, rhs; + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + return lhs < rhs; + } + }; + + //================================================================================================================== + //= StringCollationPredicateLess + //================================================================================================================== + class StringCollationPredicateLess : public IKeyPredicateLess + { + public: + StringCollationPredicateLess( ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const & i_collator ) + :m_collator( i_collator ) + { + } + + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + OUString lhs, rhs; + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + return m_collator->compareString( lhs, rhs ) < 0; + } + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const m_collator; + }; + + //================================================================================================================== + //= TypePredicateLess + //================================================================================================================== + class TypePredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + ::com::sun::star::uno::Type lhs, rhs; + if ( !( _lhs >>= lhs ) + || !( _rhs >>= rhs ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + return lhs.getTypeName() < rhs.getTypeName(); + } + }; + + //================================================================================================================== + //= EnumPredicateLess + //================================================================================================================== + class EnumPredicateLess : public IKeyPredicateLess + { + public: + EnumPredicateLess( ::com::sun::star::uno::Type const & _enumType ) + :m_enumType( _enumType ) + { + } + + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + sal_Int32 lhs(0), rhs(0); + if ( !::cppu::enum2int( lhs, _lhs ) + || !::cppu::enum2int( rhs, _rhs ) + || !_lhs.getValueType().equals( m_enumType ) + || !_rhs.getValueType().equals( m_enumType ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + return lhs < rhs; + } + + private: + ::com::sun::star::uno::Type const m_enumType; + }; + + //================================================================================================================== + //= InterfacePredicateLess + //================================================================================================================== + class InterfacePredicateLess : public IKeyPredicateLess + { + public: + virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const + { + if ( ( _lhs.getValueTypeClass() != ::com::sun::star::uno::TypeClass_INTERFACE ) + || ( _rhs.getValueTypeClass() != ::com::sun::star::uno::TypeClass_INTERFACE ) + ) + throw ::com::sun::star::lang::IllegalArgumentException(); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > lhs( _lhs, ::com::sun::star::uno::UNO_QUERY ); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > rhs( _rhs, ::com::sun::star::uno::UNO_QUERY ); + return lhs.get() < rhs.get(); + } + }; + + //================================================================================================================== + //= getStandardLessPredicate + //================================================================================================================== + /** creates a default IKeyPredicateLess instance for the given UNO type + @param i_type + the type for which a predicate instance should be created + @param i_collator + specifies a collator instance to use, or <NULL/>. If <NULL/>, strings will be compared using the <code><</code> + operator, otherwise the collator will be used. The parameter is ignored if <arg>i_type</arg> does not specify + the string type. + @return + a default implementation of IKeyPredicateLess, which is able to compare values of the given type. If no + such default implementation is known for the given type, then <NULL/> is returned. + */ + ::std::auto_ptr< IKeyPredicateLess > COMPHELPER_DLLPUBLIC + getStandardLessPredicate( + ::com::sun::star::uno::Type const & i_type, + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const & i_collator + ); + +//...................................................................................................................... +} // namespace comphelper +//...................................................................................................................... + +#endif // COMPHELPER_ANYCOMPARE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/anytostring.hxx b/include/comphelper/anytostring.hxx new file mode 100644 index 000000000000..e68779854292 --- /dev/null +++ b/include/comphelper/anytostring.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef INCLUDED_COMPHELPER_ANYTOSTRING_HXX +#define INCLUDED_COMPHELPER_ANYTOSTRING_HXX + +#include "rtl/ustring.hxx" +#include "com/sun/star/uno/Any.hxx" +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + +/** Creates a STRING representation out of an ANY value. + + @param value + ANY value + @return + STRING representation of given ANY value +*/ +COMPHELPER_DLLPUBLIC OUString anyToString( ::com::sun::star::uno::Any const & value ); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/asyncnotification.hxx b/include/comphelper/asyncnotification.hxx new file mode 100644 index 000000000000..19c1910dbc8f --- /dev/null +++ b/include/comphelper/asyncnotification.hxx @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_ASYNCNOTIFICATION_HXX +#define COMPHELPER_ASYNCNOTIFICATION_HXX + +#include "sal/config.h" + +#include "boost/scoped_ptr.hpp" +#include "comphelper/comphelperdllapi.h" +#include "rtl/ref.hxx" +#include "sal/types.h" +#include "salhelper/thread.hxx" + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= AnyEvent + //==================================================================== + /** the very basic instance to hold a description of an event + */ + class COMPHELPER_DLLPUBLIC AnyEvent : ::rtl::IReference + { + private: + oslInterlockedCount m_refCount; + + public: + AnyEvent(); + + virtual oslInterlockedCount SAL_CALL acquire(); + virtual oslInterlockedCount SAL_CALL release(); + + protected: + virtual ~AnyEvent(); + + private: + AnyEvent( AnyEvent& ); // not defined + void operator=( AnyEvent& ); // not defined + }; + + //==================================================================== + //= typedefs + //==================================================================== + typedef ::rtl::Reference< AnyEvent > AnyEventRef; + + //==================================================================== + //= IEventProcessor + //==================================================================== + /** an event processor + + @see AsyncEventNotifier + */ + class SAL_NO_VTABLE IEventProcessor + { + public: + /** process a single event + */ + virtual void processEvent( const AnyEvent& _rEvent ) = 0; + + virtual void SAL_CALL acquire() = 0; + virtual void SAL_CALL release() = 0; + + protected: + ~IEventProcessor() {} + }; + + //==================================================================== + //= AsyncEventNotifier + //==================================================================== + struct EventNotifierImpl; + + /** a helper class for notifying events asynchronously + + If you need to notify certain events to external components, you usually should + not do this while you have mutexes locked, to prevent multi-threading issues. + + However, you do not always have complete control over all mutex guards on the stack. + If, in such a case, the listener notification is one-way, you can decide to do it + asynchronously. + + The ->AsyncEventNotifier helps you to process such events asynchronously. Every + event is tied to an ->IEventProcessor which is responsible for processing it. + + The AsyncEventNotifier is implemented as a thread itself, which sleeps as long as there are no + events in the queue. As soon as you add an event, the thread is woken up, processes the event, + and sleeps again. + */ + class COMPHELPER_DLLPUBLIC AsyncEventNotifier: public salhelper::Thread + { + friend struct EventNotifierImpl; + + private: + boost::scoped_ptr< EventNotifierImpl > m_pImpl; + + SAL_DLLPRIVATE virtual ~AsyncEventNotifier(); + + // Thread + SAL_DLLPRIVATE virtual void execute(); + + public: + /** constructs a notifier thread + + @param name the thread name, see ::osl_setThreadName; must not be + null + */ + AsyncEventNotifier(char const * name); + + /** terminates the thread + + Note that this is a cooporative termination - if you call this from a thread different + from the notification thread itself, then it will block until the notification thread + finished processing the current event. If you call it from the notification thread + itself, it will return immediately, and the thread will be terminated as soon as + the current notification is finished. + */ + virtual void SAL_CALL terminate(); + + /** adds an event to the queue, together with the instance which is responsible for + processing it + + @param _rEvent + the event to add to the queue + @param _xProcessor + the processor for the event.<br/> + Beware of life time issues here. If your event processor dies or becomes otherwise + nonfunctional, you are responsible for removing all respective events from the queue. + You can do this by calling ->removeEventsForProcessor + */ + void addEvent( const AnyEventRef& _rEvent, const ::rtl::Reference< IEventProcessor >& _xProcessor ); + + /** removes all events for the given event processor from the queue + */ + void removeEventsForProcessor( const ::rtl::Reference< IEventProcessor >& _xProcessor ); + }; + + //==================================================================== + //= EventHolder + //==================================================================== + /** AnyEvent derivee holding an foreign event instance + */ + template < typename EVENT_OBJECT > + class EventHolder : public AnyEvent + { + public: + typedef EVENT_OBJECT EventObjectType; + + private: + EventObjectType m_aEvent; + + public: + inline EventHolder( const EventObjectType& _rEvent ) + :m_aEvent( _rEvent ) + { + } + + inline const EventObjectType& getEventObject() const { return m_aEvent; } + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_ASYNCNOTIFICATION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/attributelist.hxx b/include/comphelper/attributelist.hxx new file mode 100644 index 000000000000..dd10e13c70ab --- /dev/null +++ b/include/comphelper/attributelist.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_ATTRIBUTE_LIST_HXX +#define _COMPHELPER_ATTRIBUTE_LIST_HXX + +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/comphelperdllapi.h> + + +namespace comphelper +{ + +struct AttributeList_Impl; + +class COMPHELPER_DLLPUBLIC AttributeList : public ::cppu::WeakImplHelper1 +< + ::com::sun::star::xml::sax::XAttributeList +> +{ + AttributeList_Impl *m_pImpl; +public: + AttributeList(); + virtual ~AttributeList(); + + // methods that are not contained in any interface + void AddAttribute( const OUString &sName , const OUString &sType , const OUString &sValue ); + + // ::com::sun::star::xml::sax::XAttributeList + virtual sal_Int16 SAL_CALL getLength(void) + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL getTypeByName(const OUString& aName) + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL getValueByName(const OUString& aName) + throw( ::com::sun::star::uno::RuntimeException ); + +}; + +} // namespace comphelper + +#endif // _COMPHELPER_ATTRIBUTE_LIST_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/basicio.hxx b/include/comphelper/basicio.hxx new file mode 100644 index 000000000000..42eea8076e47 --- /dev/null +++ b/include/comphelper/basicio.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_BASIC_IO_HXX_ +#define _COMPHELPER_BASIC_IO_HXX_ + +#include <com/sun/star/io/XPersistObject.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +namespace stario = ::com::sun::star::io; +namespace staruno = ::com::sun::star::uno; +namespace starawt = ::com::sun::star::awt; + +// sal_Bool +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Bool& _rVal); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Bool _bVal); + +// OUString +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, OUString& _rStr); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const OUString& _rStr); + +// sal_Int16 +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int16& _rValue); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int16 _nValue); + +// sal_uInt16 +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt16& _rValue); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt16 _nValue); + +// sal_uInt32 +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt32& _rValue); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt32 _nValue); + +// sal_Int16 +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int32& _rValue); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int32 _nValue); + +// FontDescriptor +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& InStream, starawt::FontDescriptor& rVal); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& OutStream, const starawt::FontDescriptor& rVal); + +// sequences +template <class ELEMENT> +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, staruno::Sequence<ELEMENT>& _rSeq) +{ + sal_Int32 nLen = _rxInStream->readLong(); + _rSeq.realloc(nLen); + if (nLen) + { + ELEMENT* pElement = _rSeq.getArray(); + for (sal_Int32 i=0; i<nLen; ++i, ++pElement) + _rxInStream >> *pElement; + } + return _rxInStream; +} + +template <class ELEMENT> +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const staruno::Sequence<ELEMENT>& _rSeq) +{ + sal_Int32 nLen = _rSeq.getLength(); + _rxOutStream->writeLong(nLen); + if (nLen) + { + const ELEMENT* pElement = _rSeq.getConstArray(); + for (sal_Int32 i = 0; i < nLen; ++i, ++pElement) + _rxOutStream << *pElement; + } + return _rxOutStream; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_BASIC_IO_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/broadcasthelper.hxx b/include/comphelper/broadcasthelper.hxx new file mode 100644 index 000000000000..d8cf69eeb17b --- /dev/null +++ b/include/comphelper/broadcasthelper.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_BROADCASTHELPER_HXX_ +#define _COMPHELPER_BROADCASTHELPER_HXX_ + +#include <osl/mutex.hxx> +#include <cppuhelper/interfacecontainer.h> + +//... namespace comphelper ....................................................... +namespace comphelper +{ +//......................................................................... + + //================================================================================== + //= OMutexAndBroadcastHelper - a class which holds a Mutex and a OBroadcastHelper; + //= needed because when deriving from OPropertySetHelper, + //= the OBroadcastHelper has to be initialized before + //= the OPropertySetHelper + //================================================================================== + class OMutexAndBroadcastHelper + { + protected: + ::osl::Mutex m_aMutex; + ::cppu::OBroadcastHelper m_aBHelper; + + public: + OMutexAndBroadcastHelper() : m_aBHelper( m_aMutex ) { } + + ::osl::Mutex& GetMutex() { return m_aMutex; } + ::cppu::OBroadcastHelper& GetBroadcastHelper() { return m_aBHelper; } + const ::cppu::OBroadcastHelper& GetBroadcastHelper() const { return m_aBHelper; } + + }; + + // base class for all classes who are derived from OPropertySet and from OComponent + // @deprecated, you should use cppu::BaseMutex instead (cppuhelper/basemutex.hxx) + + class OBaseMutex + { + protected: + mutable ::osl::Mutex m_aMutex; + }; +} +#endif // _COMPHELPER_BROADCASTHELPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/classids.hxx b/include/comphelper/classids.hxx new file mode 100644 index 000000000000..39ab6095802e --- /dev/null +++ b/include/comphelper/classids.hxx @@ -0,0 +1,388 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_CLASSIDS_HXX +#define _COMPHELPER_CLASSIDS_HXX + +/* + * StarWriter + */ + +/* 3.0 */ + +#define SO3_SW_CLASSID_30 \ + 0xDC5C7E40L, 0xB35C, 0x101B, 0x99, 0x61, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +/* 4.0 */ + +#define SO3_SW_CLASSID_40 \ + 0x8b04e9b0, 0x420e, 0x11d0, 0xa4, 0x5e, 0x0, \ + 0xa0, 0x24, 0x9d, 0x57, 0xb1 + +/* 5.0 */ + +#define SO3_SW_CLASSID_50 \ + 0xc20cf9d1, 0x85ae, 0x11d1, 0xaa, 0xb4, 0x0, \ + 0x60, 0x97, 0xda, 0x56, 0x1a + + /* 6.0, 7, 8 */ + +#define SO3_SW_CLASSID_60 \ + 0x8BC6B165, 0xB1B2, 0x4EDD, 0xAA, 0x47, 0xDA, \ + 0xE2, 0xEE, 0x68, 0x9D, 0xD6 + + /* ole embed 6.0, 7 */ + +#define SO3_SW_OLE_EMBED_CLASSID_60 \ + 0x30a2652a, 0xddf7, 0x45e7, 0xac, 0xa6, 0x3e, \ + 0xab, 0x26, 0xfc, 0x8a, 0x4e + + /* ole embed 8 */ + +#define SO3_SW_OLE_EMBED_CLASSID_8 \ + 0xf616b81f, 0x7bb8, 0x4f22, 0xb8, 0xa5, 0x47, \ + 0x42, 0x8d, 0x59, 0xf8, 0xad + +/* aktuell */ + +#define SO3_SW_CLASSID SO3_SW_CLASSID_60 + +/* + * StarWriter/Web + */ + +/* 4.0 */ + +#define SO3_SWWEB_CLASSID_40 \ + 0xf0caa840, 0x7821, 0x11d0, 0xa4, 0xa7, 0x0, \ + 0xa0, 0x24, 0x9d, 0x57, 0xb1 + +/* 5.0 */ + +#define SO3_SWWEB_CLASSID_50 \ + 0xc20cf9d2, 0x85ae, 0x11d1, 0xaa, 0xb4, 0x0, \ + 0x60, 0x97, 0xda, 0x56, 0x1a + +/* 6.0, 7, 8 */ + +#define SO3_SWWEB_CLASSID_60 \ + 0xA8BBA60C, 0x7C60, 0x4550, 0x91, 0xCE, 0x39, \ + 0xC3, 0x90, 0x3F, 0xAC, 0x5E + +/* aktuell */ + +#define SO3_SWWEB_CLASSID SO3_SWWEB_CLASSID_60 + +/* + * Globaldokument + */ + +/* 4.0 */ + +#define SO3_SWGLOB_CLASSID_40 \ + 0x340ac970, 0xe30d, 0x11d0, 0xa5, 0x3f, 0x0, \ + 0xa0, 0x24, 0x9d, 0x57, 0xb1 + +/* 5.0 */ + +#define SO3_SWGLOB_CLASSID_50 \ + 0xc20cf9d3, 0x85ae, 0x11d1, 0xaa, 0xb4, 0x0, \ + 0x60, 0x97, 0xda, 0x56, 0x1a + +/* 6.0, 7, 8 */ + +#define SO3_SWGLOB_CLASSID_60 \ + 0xB21A0A7C, 0xE403, 0x41FE, 0x95, 0x62, 0xBD, \ + 0x13, 0xEA, 0x6F, 0x15, 0xA0 + +/* aktuell */ + +#define SO3_SWGLOB_CLASSID SO3_SWGLOB_CLASSID_60 + +//--------------------------------------------------- + +/* + * StarCalc + */ + +/* 3.0 */ + +#define SO3_SC_CLASSID_30 \ + 0x3F543FA0L, 0xB6A6, 0x101B, 0x99, 0x61, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +/* 4.0 */ + +#define SO3_SC_CLASSID_40 \ + 0x6361d441L, 0x4235, 0x11d0, 0x89, 0xcb, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 5.0 */ + +#define SO3_SC_CLASSID_50 \ + 0xc6a5b861L, 0x85d6, 0x11d1, 0x89, 0xcb, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 6.0 */ + +#define SO3_SC_CLASSID_60 \ + 0x47BBB4CB, 0xCE4C, 0x4E80, 0xA5, 0x91, 0x42, \ + 0xD9, 0xAE, 0x74, 0x95, 0x0F + +/* ole embed 6.0, 7 */ + +#define SO3_SC_OLE_EMBED_CLASSID_60 \ + 0x7b342dc4, 0x139a, 0x4a46, 0x8a, 0x93, 0xdb, \ + 0x8, 0x27, 0xcc, 0xee, 0x9c + +/* ole embed 8 */ + +#define SO3_SC_OLE_EMBED_CLASSID_8 \ + 0x7fa8ae11, 0xb3e3, 0x4d88, 0xaa, 0xbf, 0x25, \ + 0x55, 0x26, 0xcd, 0x1c, 0xe8 + +/* aktuell */ + +#define SO3_SC_CLASSID SO3_SC_CLASSID_60 + +/**************************************************** +* StarImpress +****************************************************/ + +/* 3.0 */ + +#define SO3_SIMPRESS_CLASSID_30 \ + 0xAF10AAE0L, 0xB36D, 0x101B, 0x99, 0x61, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +/* 4.0 */ + +#define SO3_SIMPRESS_CLASSID_40 \ + 0x12d3cc0L, 0x4216, 0x11d0, 0x89, 0xcb, 0x0, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 5.0 */ + +#define SO3_SIMPRESS_CLASSID_50 \ + 0x565c7221L, 0x85bc, 0x11d1, 0x89, 0xd0, 0x0, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 6.0 */ + +#define SO3_SIMPRESS_CLASSID_60 \ + 0x9176E48A, 0x637A, 0x4D1F, 0x80, 0x3B, 0x99, \ + 0xD9, 0xBF, 0xAC, 0x10, 0x47 + +/* ole embed 6.0, 7 */ + +#define SO3_SIMPRESS_OLE_EMBED_CLASSID_60 \ + 0xe5a0b632, 0xdfba, 0x4549, 0x93, 0x46, 0xe4, \ + 0x14, 0xda, 0x6, 0xe6, 0xf8 + +/* ole embed 8 */ + +#define SO3_SIMPRESS_OLE_EMBED_CLASSID_8 \ + 0xee5d1ea4, 0xd445, 0x4289, 0xb2, 0xfc, 0x55, \ + 0xfc, 0x93, 0x69, 0x39, 0x17 + +/* aktuell */ + +#define SO3_SIMPRESS_CLASSID SO3_SIMPRESS_CLASSID_60 + +/**************************************************** +* StarDraw +****************************************************/ + +/* 5.0 */ + +#define SO3_SDRAW_CLASSID_50 \ + 0x2e8905a0L, 0x85bd, 0x11d1, 0x89, 0xd0, 0x0, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 6.0 */ +#define SO3_SDRAW_CLASSID_60 \ + 0x4BAB8970, 0x8A3B, 0x45B3, 0x99, 0x1C, 0xCB, \ + 0xEE, 0xAC, 0x6B, 0xD5, 0xE3 + +/* ole embed 6.0, 7 */ + +#define SO3_SDRAW_OLE_EMBED_CLASSID_60 \ + 0x41662fc2, 0xd57, 0x4aff, 0xab, 0x27, 0xad, \ + 0x2e, 0x12, 0xe7, 0xc2, 0x73 + +/* ole embed 8 */ + +#define SO3_SDRAW_OLE_EMBED_CLASSID_8 \ + 0x448bb771, 0xcfe2, 0x47c4, 0xbc, 0xdf, 0x1f, \ + 0xbf, 0x37, 0x8e, 0x20, 0x2c + +/* aktuell */ + +#define SO3_SDRAW_CLASSID SO3_SDRAW_CLASSID_60 + +/**************************************************** +* StarChart +****************************************************/ + +/* 3.0 */ + +#define SO3_SCH_CLASSID_30 \ + 0xFB9C99E0L, 0x2C6D, 0x101C, 0x8E, 0x2C, 0x00, \ + 0x00, 0x1B, 0x4C, 0xC7, 0x11 + +/* 4.0 */ + +#define SO3_SCH_CLASSID_40 \ + 0x2b3b7e0L, 0x4225, 0x11d0, 0x89, 0xca, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 5.0 */ + +#define SO3_SCH_CLASSID_50 \ + 0xbf884321L, 0x85dd, 0x11d1, 0x89, 0xd0, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 6.0 */ + +#define SO3_SCH_CLASSID_60 \ + 0x12DCAE26, 0x281F, 0x416F, 0xA2, 0x34, 0xC3, \ + 0x08, 0x61, 0x27, 0x38, 0x2E + +/* ole embed 6.0, 7 */ + +#define SO3_SCH_OLE_EMBED_CLASSID_60 \ + 0xd415cd93, 0x35c4, 0x4c6f, 0x81, 0x9d, 0xa6, \ + 0x64, 0xa1, 0xc8, 0x13, 0xae + +/* ole embed 8 */ + +#define SO3_SCH_OLE_EMBED_CLASSID_8 \ + 0xdd0a57f, 0xcf3b, 0x4fd2, 0xbd, 0xa4, 0x94, \ + 0x42, 0x71, 0x9b, 0x2a, 0x73 + +/* aktuell */ + +#define SO3_SCH_CLASSID SO3_SCH_CLASSID_60 + +/**************************************************** +* StarImage +****************************************************/ + +/* 3.0 */ + +#define SO3_SIM_CLASSID_30 \ + 0xEA60C941L, 0x2C6C, 0x101C, 0x8E, 0x2C, 0x00, \ + 0x00, 0x1B, 0x4C, 0xC7, 0x11 + +/* 4.0 */ + +#define SO3_SIM_CLASSID_40 \ + 0x447BB8A0L, 0x41FB, 0x11D0, 0x89, 0xCA, 0x00, \ + 0x80, 0x29, 0xE4, 0xB0, 0xB1 + +/* 5.0 */ + +#define SO3_SIM_CLASSID_50 \ + 0x65c68d00L, 0x85de, 0x11d1, 0x89, 0xd0, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* aktuell */ + +#define SO3_SIM_CLASSID SO3_SIM_CLASSID_50 + +/*************************************************** +* StarMath +***************************************************/ + +/* 3.0 */ + +#define SO3_SM_CLASSID_30 \ + 0xD4590460L, 0x35FD, 0x101C, 0xB1, 0x2A, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +/* 4.0 */ + +#define SO3_SM_CLASSID_40 \ + 0x2b3b7e1L, 0x4225, 0x11d0, 0x89, 0xca, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 5.0 */ + +#define SO3_SM_CLASSID_50 \ + 0xffb5e640L, 0x85de, 0x11d1, 0x89, 0xd0, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* 6.0, 7, 8 */ + +#define SO3_SM_CLASSID_60 \ + 0x078B7ABA, 0x54FC, 0x457F, 0x85, 0x51, 0x61, \ + 0x47, 0xE7, 0x76, 0xA9, 0x97 + +/* ole embed 6.0, 7 */ + +#define SO3_SM_OLE_EMBED_CLASSID_60 \ + 0xd0484de6, 0xaaee, 0x468a, 0x99, 0x1f, 0x8d, \ + 0x4b, 0x7, 0x37, 0xb5, 0x7a + +/* ole embed 8 */ + +#define SO3_SM_OLE_EMBED_CLASSID_8 \ + 0xd2d59cd1, 0xa6a, 0x4d36, 0xae, 0x20, 0x47, \ + 0x81, 0x70, 0x77, 0xd5, 0x7c + +/* aktuell */ + +#define SO3_SM_CLASSID SO3_SM_CLASSID_60 + +#define SO3_OUT_CLASSID \ + 0x970b1e82, 0xcf2d, 0x11cf, 0x89, 0xca, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +#define SO3_DUMMY_CLASSID \ + 0x970b1fff, 0xcf2d, 0x11cf, \ + 0x89,0xca,0x00,0x80,0x29,0xe4,0xb0,0xb1 + +#define SO3_APPLET_CLASSID \ + 0x970b1e81, 0xcf2d, 0x11cf, \ + 0x89,0xca,0x00,0x80,0x29,0xe4,0xb0,0xb1 + +#define SO3_PLUGIN_CLASSID \ + 0x4caa7761, 0x6b8b, 0x11cf, \ + 0x89,0xca,0x0,0x80,0x29,0xe4,0xb0,0xb1 + +#define SO3_IFRAME_CLASSID \ + 0x1a8a6701, 0xde58, 0x11cf, \ + 0x89, 0xca, 0x0, 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +#define SO3_GLOBAL_CLASSID \ + 0x475198a8, 0x694c, 0x4bd8, \ + 0xb0, 0x2f, 0xd9, 0xb7, 0x6b, 0xcf, 0x31, 0x28 + +#define SO3_RPT_CLASSID_90 \ + 0xd7896d52, 0xb7af, 0x4820, \ + 0x9d, 0xfe, 0xd4, 0x04, 0xd0, 0x15, 0x96, 0x0f + +#define SO3_RPT_SCH_CLASSID_90 \ + 0x80243d39, 0x6741, 0x46c5, \ + 0x92, 0x6e, 0x06, 0x91, 0x64, 0xff, 0x87, 0xbb + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/comphelperdllapi.h b/include/comphelper/comphelperdllapi.h new file mode 100644 index 000000000000..88d35f61c359 --- /dev/null +++ b/include/comphelper/comphelperdllapi.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef INCLUDED_COMPHELPERDLLAPI_H +#define INCLUDED_COMPHELPERDLLAPI_H + +#include "sal/types.h" + +#if defined(COMPHELPER_DLLIMPLEMENTATION) +#define COMPHELPER_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define COMPHELPER_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define COMPHELPER_DLLPRIVATE SAL_DLLPRIVATE + +#endif /* INCLUDED_COMPHELPERDLLAPI_H */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/componentbase.hxx b/include/comphelper/componentbase.hxx new file mode 100644 index 000000000000..b4035a60f77b --- /dev/null +++ b/include/comphelper/componentbase.hxx @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_COMPONENTBASE_HXX +#define COMPHELPER_COMPONENTBASE_HXX + +#include "comphelper/comphelperdllapi.h" +#include <cppuhelper/interfacecontainer.hxx> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= ComponentBase + //==================================================================== + class COMPHELPER_DLLPUBLIC ComponentBase + { + protected: + /** creates a ComponentBase instance + + The instance is not initialized. As a consequence, every ComponentMethodGuard instantiated for + this component will throw a <type scope="com::sun::star::lang">NotInitializedException</type>, + until ->setInitialized() is called. + */ + ComponentBase( ::cppu::OBroadcastHelper& _rBHelper ) + :m_rBHelper( _rBHelper ) + ,m_bInitialized( false ) + { + } + + struct NoInitializationNeeded { }; + + /** creates a ComponentBase instance + + The instance is already initialized, so there's no need to call setInitialized later on. Use this + constructor for component implementations which do not require explicit initialization. + */ + ComponentBase( ::cppu::OBroadcastHelper& _rBHelper, NoInitializationNeeded ) + :m_rBHelper( _rBHelper ) + ,m_bInitialized( true ) + { + } + + ~ComponentBase() {} + + /** marks the instance as initialized + + Subsequent instantiations of a ComponentMethodGuard won't throw the NotInitializedException now. + */ + inline void setInitialized() { m_bInitialized = true; } + + public: + /// helper struct to grant access to selected public methods to the ComponentMethodGuard class + struct GuardAccess { friend class ComponentMethodGuard; private: GuardAccess() { } }; + + /// retrieves the component's mutex + inline ::osl::Mutex& getMutex( GuardAccess ) { return getMutex(); } + /// checks whether the component is already disposed, throws a DisposedException if so. + inline void checkDisposed( GuardAccess ) const { impl_checkDisposed_throw(); } + /// checks whether the component is already initialized, throws a NotInitializedException if not. + inline void checkInitialized( GuardAccess ) const { impl_checkInitialized_throw(); } + + protected: + /// retrieves the component's broadcast helper + inline ::cppu::OBroadcastHelper& getBroadcastHelper() { return m_rBHelper; } + /// retrieves the component's mutex + inline ::osl::Mutex& getMutex() { return m_rBHelper.rMutex; } + /// determines whether the instance is already disposed + inline bool impl_isDisposed() const { return m_rBHelper.bDisposed; } + + /// checks whether the component is already disposed. Throws a DisposedException if so. + void impl_checkDisposed_throw() const; + + /// checks whether the component is already initialized. Throws a NotInitializedException if not. + void impl_checkInitialized_throw() const; + + /// determines whether the component is already initialized + inline bool + impl_isInitialized_nothrow() const { return m_bInitialized; } + + /** returns the context to be used when throwing exceptions + + The default implementation returns <NULL/>. + */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + getComponent() const; + + private: + ::cppu::OBroadcastHelper& m_rBHelper; + bool m_bInitialized; + }; + + class ComponentMethodGuard + { + public: + enum MethodType + { + /// allow the method to be called only when being initialized and not being disposed + Default, + /// allow the method to be called without being initialized + WithoutInit + + }; + + ComponentMethodGuard( ComponentBase& _rComponent, const MethodType _eType = Default ) + :m_aMutexGuard( _rComponent.getMutex( ComponentBase::GuardAccess() ) ) + { + if ( _eType != WithoutInit ) + _rComponent.checkInitialized( ComponentBase::GuardAccess() ); + _rComponent.checkDisposed( ComponentBase::GuardAccess() ); + } + + ~ComponentMethodGuard() + { + } + + inline void clear() + { + m_aMutexGuard.clear(); + } + inline void reset() + { + m_aMutexGuard.reset(); + } + + private: + ::osl::ResettableMutexGuard m_aMutexGuard; + }; + +//........................................................................ +} // namespace ComponentBase +//........................................................................ + +#endif // COMPHELPER_COMPONENTBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/componentcontext.hxx b/include/comphelper/componentcontext.hxx new file mode 100644 index 000000000000..d6461502be54 --- /dev/null +++ b/include/comphelper/componentcontext.hxx @@ -0,0 +1,243 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_COMPONENTCONTEXT_HXX +#define COMPHELPER_COMPONENTCONTEXT_HXX + +#include <comphelper/comphelperdllapi.h> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= ComponentContext + //==================================================================== + /** a helper class for working with a component context + */ + class COMPHELPER_DLLPUBLIC ComponentContext + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory > m_xORB; + + public: + /** constructs an instance + @param _rxContext + the component context to manage + @throws ::com::sun::star::lang::NullPointerException + if the given context, or its component factory, are <NULL/> + */ + ComponentContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext ); + + /** constructs an instance + @param _rxLegacyFactory + the legacy service factor to obtain the <type scope="com::sun::star::uno">XComponentContext</type> from + @throws ::com::sun::star::uno::RuntimeException + if the given factory or does not have a DefaultContext property to obtain + a component context + @throws ::com::sun::star::lang::NullPointerException + if the given factory is <NULL/>, or provides a component context being <NULL/>, or provides + a component context whose component factory is <NULL/> + */ + ComponentContext( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxLegacyFactory ); + + /** returns the ->XComponentContext interface + */ + inline ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + getUNOContext() const { return m_xContext; } + + /** determines whether the context is not <NULL/> + */ + inline sal_Bool is() const + { + return m_xContext.is(); + } + + /** creates a component using our component factory/context + @throws ::com::sun::star::uno::Exception + @return + <TRUE/> if and only if the component could be successfully created + */ + template < typename INTERFACE > + bool createComponent( const OUString& _rServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const + { + _out_rxComponent.clear(); + _out_rxComponent = _out_rxComponent.query( + m_xORB->createInstanceWithContext( _rServiceName, m_xContext ) + ); + return _out_rxComponent.is(); + } + + /** creates a component using our component factory/context + @throws ::com::sun::star::uno::Exception + @return + <TRUE/> if and only if the component could be successfully created + */ + template < typename INTERFACE > + bool createComponent( const sal_Char* _pAsciiServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const + { + return createComponent( OUString::createFromAscii( _pAsciiServiceName ), _out_rxComponent ); + } + + /** creates a component using our component factory/context, passing creation arguments + @throws ::com::sun::star::uno::Exception + @return + <TRUE/> if and only if the component could be successfully created + */ + template < typename INTERFACE > + bool createComponentWithArguments( const OUString& _rServiceName, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const + { + _out_rxComponent.clear(); + _out_rxComponent = _out_rxComponent.query( + m_xORB->createInstanceWithArgumentsAndContext( _rServiceName, _rArguments, m_xContext ) + ); + return _out_rxComponent.is(); + } + + /** creates a component using our component factory/context, passing creation arguments + @throws ::com::sun::star::uno::Exception + @return + <TRUE/> if and only if the component could be successfully created + */ + template < typename INTERFACE > + bool createComponentWithArguments( const sal_Char* _pAsciiServiceName, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const + { + return createComponentWithArguments( OUString::createFromAscii( _pAsciiServiceName ), _rArguments, _out_rxComponent ); + } + + /** creates a component using our component factory/context + + @throws ::com::sun::star::lang::ServiceNotRegisteredException + if the given service is not registered + @throws Exception + if an exception occurred during creating the component + @return + the newly created component. Is never <NULL/>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const OUString& _rServiceName ) const; + + /** creates a component using our component factory/context + + @throws ::com::sun::star::lang::ServiceNotRegisteredException + if the given service is not registered + @throws Exception + if an exception occurred during creating the component + @return + the newly created component. Is never <NULL/>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const sal_Char* _pAsciiServiceName ) const + { + return createComponent( OUString::createFromAscii( _pAsciiServiceName ) ); + } + + /** creates a component using our component factory/context, passing creation arguments + + @throws ::com::sun::star::lang::ServiceNotRegisteredException + if the given service is not registered + @throws Exception + if an exception occurred during creating the component + @return + the newly created component. Is never <NULL/>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponentWithArguments( + const OUString& _rServiceName, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments + ) const; + + /** creates a component using our component factory/context, passing creation arguments + + @throws ::com::sun::star::lang::ServiceNotRegisteredException + if the given service is not registered + @throws Exception + if an exception occurred during creating the component + @return + the newly created component. Is never <NULL/>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponentWithArguments( + const sal_Char* _pAsciiServiceName, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments + ) const + { + return createComponentWithArguments( OUString::createFromAscii( _pAsciiServiceName ), _rArguments ); + } + + /** retrieves a singleton instance from the context + + Singletons are collected below the <code>/singletons</code> key in a component context, + so accessing them means retrieving the value under <code>/singletons/<instance_name></code>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getSingleton( const OUString& _rInstanceName ) const; + + /** retrieves a singleton instance from the context + + Singletons are collected below the <code>/singletons</code> key in a component context, + so accessing them means retrieving the value under <code>/singletons/<instance_name></code>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getSingleton( const sal_Char* _pAsciiInstanceName ) const + { + return getSingleton( OUString::createFromAscii( _pAsciiInstanceName ) ); + } + + /** returns the ->XMultiServiceFactory interface of ->m_xORB, for passing to + older code which does not yet support ->XMultiComponentFactory + @throws ::com::sun::star::uno::RuntimeException + if our our component factory does not support this interface + */ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + getLegacyServiceFactory() const; + + /** retrieves a value from our component context + @param _rName + the name of the value to retrieve + @return + the context value with the given name + @seealso XComponentContext::getValueByName + @seealso getContextValueByAsciiName + */ + ::com::sun::star::uno::Any + getContextValueByName( const OUString& _rName ) const; + + /** retrieves a value from our component context, specified by 8-bit ASCII string + @param _rName + the name of the value to retrieve, as ASCII character string + @return + the context value with the given name + @seealso XComponentContext::getValueByName + @seealso getContextValueByName + */ + inline ::com::sun::star::uno::Any + getContextValueByAsciiName( const sal_Char* _pAsciiName ) const + { + return getContextValueByName( OUString::createFromAscii( _pAsciiName ) ); + } + + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_COMPONENTCONTEXT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/componentguard.hxx b/include/comphelper/componentguard.hxx new file mode 100644 index 000000000000..eb1cfbcc24a8 --- /dev/null +++ b/include/comphelper/componentguard.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_COMPONENTGUARD_HXX +#define COMPHELPER_COMPONENTGUARD_HXX + +#include <com/sun/star/lang/DisposedException.hpp> + +#include <cppuhelper/weak.hxx> +#include <cppuhelper/interfacecontainer.hxx> + +//...................................................................................................................... +namespace comphelper +{ +//...................................................................................................................... + + //================================================================================================================== + //= ComponentGuard + //================================================================================================================== + class ComponentGuard + { + public: + ComponentGuard( ::cppu::OWeakObject& i_component, ::cppu::OBroadcastHelper & i_broadcastHelper ) + :m_aGuard( i_broadcastHelper.rMutex ) + { + if ( i_broadcastHelper.bDisposed ) + throw ::com::sun::star::lang::DisposedException( OUString(), &i_component ); + } + + ~ComponentGuard() + { + } + + void clear() { m_aGuard.clear(); } + void reset() { m_aGuard.reset(); } + + private: + ::osl::ResettableMutexGuard m_aGuard; + }; + +//...................................................................................................................... +} // namespace comphelper +//...................................................................................................................... + +#endif // COMPHELPER_COMPONENTGUARD_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/componentmodule.hxx b/include/comphelper/componentmodule.hxx new file mode 100644 index 000000000000..9ce8a137ede2 --- /dev/null +++ b/include/comphelper/componentmodule.hxx @@ -0,0 +1,261 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef COMPHELPER_INC_COMPHELPER_COMPONENTMODULE_HXX +#define COMPHELPER_INC_COMPHELPER_COMPONENTMODULE_HXX + +#include <comphelper/comphelperdllapi.h> + +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppuhelper/factory.hxx> + +#include <osl/mutex.hxx> + +#include <rtl/string.hxx> +#include <rtl/instance.hxx> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + /** factory factory declaration + */ + typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > (SAL_CALL *FactoryInstantiation) + ( + ::cppu::ComponentFactoryFunc _pFactoryFunc, + OUString const& _rComponentName, + ::com::sun::star::uno::Sequence< OUString > const & _rServiceNames, + rtl_ModuleCount* + ) SAL_THROW(()); + + //========================================================================= + //= ComponentDescription + //========================================================================= + struct COMPHELPER_DLLPUBLIC ComponentDescription + { + /// the implementation name of the component + OUString sImplementationName; + /// the services supported by the component implementation + ::com::sun::star::uno::Sequence< OUString > aSupportedServices; + /** the name under which the component implementation should be registered as singleton, + or empty if the component does not implement a singleton. + */ + OUString sSingletonName; + /// the function to create an instance of the component + ::cppu::ComponentFactoryFunc pComponentCreationFunc; + /// the function to create a factory for the component (usually <code>::cppu::createSingleComponentFactory</code>) + FactoryInstantiation pFactoryCreationFunc; + + ComponentDescription() + :sImplementationName() + ,aSupportedServices() + ,sSingletonName() + ,pComponentCreationFunc( NULL ) + ,pFactoryCreationFunc( NULL ) + { + } + + ComponentDescription( + const OUString& _rImplementationName, + const ::com::sun::star::uno::Sequence< OUString >& _rSupportedServices, + const OUString& _rSingletonName, + ::cppu::ComponentFactoryFunc _pComponentCreationFunc, + FactoryInstantiation _pFactoryCreationFunc + ) + :sImplementationName( _rImplementationName ) + ,aSupportedServices( _rSupportedServices ) + ,sSingletonName( _rSingletonName ) + ,pComponentCreationFunc( _pComponentCreationFunc ) + ,pFactoryCreationFunc( _pFactoryCreationFunc ) + { + } + }; + + //========================================================================= + //= OModule + //========================================================================= + class OModuleImpl; + class COMPHELPER_DLLPUBLIC OModule + { + private: + oslInterlockedCount m_nClients; /// number of registered clients + OModuleImpl* m_pImpl; /// impl class. lives as long as at least one client for the module is registered + + protected: + mutable ::osl::Mutex m_aMutex; /// access safety + + public: + OModule(); + + virtual ~OModule(); + + /** register a component implementing a service with the given data. + @param _rImplementationName + the implementation name of the component + @param _rServiceNames + the services the component supports + @param _pCreateFunction + a function for creating an instance of the component + @param _pFactoryFunction + a function for creating a factory for that component + */ + void registerImplementation( + const OUString& _rImplementationName, + const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames, + ::cppu::ComponentFactoryFunc _pCreateFunction, + FactoryInstantiation _pFactoryFunction = ::cppu::createSingleComponentFactory ); + + /** registers a component given by <type>ComponentDescription</type> + */ + void registerImplementation( const ComponentDescription& _rComp ); + + /** creates a Factory for the component with the given implementation name. + <p>Usually used from within component_getFactory.<p/> + @param _pImplementationName + the implementation name of the component + @return + the XInterface access to a factory for the component + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory( + const OUString& _rImplementationName ); + + /** version of getComponentFactory which directly takes the char argument you got in your component_getFactory call + */ + void* getComponentFactory( const sal_Char* _pImplementationName ); + + public: + class ClientAccess { friend class OModuleClient; private: ClientAccess() { } }; + /// register a client for the module + void registerClient( ClientAccess ); + /// revoke a client for the module + void revokeClient( ClientAccess ); + + protected: + /** called when the first client has been registered + @precond + <member>m_aMutex</member> is locked + */ + virtual void onFirstClient(); + + /** called when the last client has been revoked + @precond + <member>m_aMutex</member> is locked + */ + virtual void onLastClient(); + + private: + OModule( const OModule& ); // never implemented + OModule& operator=( const OModule& ); // never implemented + }; + + //========================================================================= + //= OModuleClient + //========================================================================= + /** base class for objects which uses any global module-specific resources + */ + class COMPHELPER_DLLPUBLIC OModuleClient + { + protected: + OModule& m_rModule; + + public: + OModuleClient( OModule& _rModule ) :m_rModule( _rModule ) { m_rModule.registerClient( OModule::ClientAccess() ); } + ~OModuleClient() { m_rModule.revokeClient( OModule::ClientAccess() ); } + }; + + //========================================================================== + //= OAutoRegistration + //========================================================================== + template <class TYPE> + class OAutoRegistration + { + public: + /** automatically provides all component information to an OModule instance + <p>Assumed that the template argument has the three methods + <ul> + <li><code>static OUString getImplementationName_static()</code><li/> + <li><code>static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static()</code><li/> + <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code> + </li> + <ul/> + the instantiation of this object will automatically register the class via <member>OModule::registerImplementation</member>. + <p/> + The factory creation function used is <code>::cppu::createSingleComponentFactory</code>. + */ + OAutoRegistration( OModule& _rModule ); + }; + + template <class TYPE> + OAutoRegistration<TYPE>::OAutoRegistration( OModule& _rModule ) + { + _rModule.registerImplementation( + TYPE::getImplementationName_static(), + TYPE::getSupportedServiceNames_static(), + TYPE::Create + ); + } + + //========================================================================== + //= OSingletonRegistration + //========================================================================== + template <class TYPE> + class OSingletonRegistration + { + public: + /** automatically provides all component information to an OModule instance, + for a singleton component + + <p>Assumed that the template argument has the three methods + <ul> + <li><code>static OUString getImplementationName_static()</code><li/> + <li><code>static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_static()</code><li/> + <li><code>static OUString getSingletonName_static()</code></li> + <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code> + </li> + <ul/> + the instantiation of this object will automatically register the class via <member>OModule::registerImplementation</member>. + </p> + */ + OSingletonRegistration( OModule& _rModule ); + }; + + template <class TYPE> + //-------------------------------------------------------------------------- + OSingletonRegistration<TYPE>::OSingletonRegistration( OModule& _rModule ) + { + _rModule.registerImplementation( ComponentDescription( + TYPE::getImplementationName_static(), + TYPE::getSupportedServiceNames_static(), + TYPE::getSingletonName_static(), + &TYPE::Create, + &::cppu::createSingleComponentFactory + ) ); + } + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_INC_COMPHELPER_COMPONENTMODULE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/configuration.hxx b/include/comphelper/configuration.hxx new file mode 100644 index 000000000000..8eecc7facd91 --- /dev/null +++ b/include/comphelper/configuration.hxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_COMPHELPER_CONFIGURATION_HXX +#define INCLUDED_COMPHELPER_CONFIGURATION_HXX + +#include "sal/config.h" + +#include "boost/noncopyable.hpp" +#include "boost/optional.hpp" +#include "boost/shared_ptr.hpp" +#include "com/sun/star/uno/Any.hxx" +#include "com/sun/star/uno/Reference.hxx" +#include "comphelper/comphelperdllapi.h" +#include "comphelper/processfactory.hxx" +#include "sal/types.h" + +namespace com { namespace sun { namespace star { + namespace configuration { class XReadWriteAccess; } + namespace container { + class XHierarchicalNameAccess; + class XHierarchicalNameReplace; + class XNameAccess; + class XNameContainer; + } + namespace uno { class XComponentContext; } +} } } + +namespace comphelper { + +namespace detail { class ConfigurationWrapper; } + +/// A batch of configuration changes that is committed as a whole. +/// +/// Client code needs to call commit explicitly; otherwise the changes are lost +/// when the instance is destroyed. +/// +/// This is the only class from this header file that client code should use +/// directly. +class COMPHELPER_DLLPUBLIC ConfigurationChanges: private boost::noncopyable { +public: + static boost::shared_ptr< ConfigurationChanges > create( + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()); + + ~ConfigurationChanges(); + + void commit() const; + +private: + SAL_DLLPRIVATE ConfigurationChanges( + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context); + + SAL_DLLPRIVATE void setPropertyValue( + OUString const & path, com::sun::star::uno::Any const & value) + const; + + SAL_DLLPRIVATE com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameReplace > + getGroup(OUString const & path) const; + + SAL_DLLPRIVATE + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > + getSet(OUString const & path) const; + + com::sun::star::uno::Reference< + com::sun::star::configuration::XReadWriteAccess > access_; + + friend class detail::ConfigurationWrapper; +}; + +namespace detail { + +/// @internal +class COMPHELPER_DLLPUBLIC ConfigurationWrapper: private boost::noncopyable { +public: + static ConfigurationWrapper const & get( + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context); + + SAL_DLLPRIVATE explicit ConfigurationWrapper( + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context); + + SAL_DLLPRIVATE ~ConfigurationWrapper(); + + com::sun::star::uno::Any getPropertyValue(OUString const & path) const; + + void setPropertyValue( + boost::shared_ptr< ConfigurationChanges > const & batch, + OUString const & path, com::sun::star::uno::Any const & value) + const; + + com::sun::star::uno::Any getLocalizedPropertyValue( + OUString const & path) const; + + void setLocalizedPropertyValue( + boost::shared_ptr< ConfigurationChanges > const & batch, + OUString const & path, com::sun::star::uno::Any const & value) + const; + + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > + getGroupReadOnly(OUString const & path) const; + + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameReplace > + getGroupReadWrite( + boost::shared_ptr< ConfigurationChanges > const & batch, + OUString const & path) const; + + com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > + getSetReadOnly(OUString const & path) const; + + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > + getSetReadWrite( + boost::shared_ptr< ConfigurationChanges > const & batch, + OUString const & path) const; + + boost::shared_ptr< ConfigurationChanges > createChanges() const; + +private: + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + context_; + + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > access_; +}; + +/// @internal +template< typename T > struct Convert: private boost::noncopyable { + static com::sun::star::uno::Any toAny(T const & value) + { return com::sun::star::uno::makeAny(value); } + + static T fromAny(com::sun::star::uno::Any const & value) + { return value.get< T >(); } + +private: + Convert(); // not defined + ~Convert(); // not defined +}; + +/// @internal +template< typename T > struct Convert< boost::optional< T > >: + private boost::noncopyable +{ + static com::sun::star::uno::Any toAny(boost::optional< T > const & value) { + return value + ? com::sun::star::uno::makeAny(value.get()) + : com::sun::star::uno::Any(); + } + + static boost::optional< T > fromAny(com::sun::star::uno::Any const & value) + { + return value.hasValue() + ? boost::optional< T >(value.get< T >()) : boost::optional< T >(); + } + +private: + Convert(); // not defined + ~Convert(); // not defined +}; + +} + +/// A type-safe wrapper around a (non-localized) configuration property. +/// +/// Automatically generated headers for the various configuration properties +/// derive from this template and make available its member functions to access +/// each given configuration property. +template< typename T, typename U > struct ConfigurationProperty: + private boost::noncopyable +{ + /// Get the value of the given (non-localized) configuration property. + /// + /// For nillable properties, U is of type boost::optional<U'>. + static U get( + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + // Folding this into one statement causes a bogus error at least with + // Red Hat GCC 4.6.2-1: + com::sun::star::uno::Any a( + detail::ConfigurationWrapper::get(context).getPropertyValue( + T::path())); + return detail::Convert< U >::fromAny(a); + } + + /// Set the value of the given (non-localized) configuration property, via a + /// given changes batch. + /// + /// For nillable properties, U is of type boost::optional<U'>. + static void set( + U const & value, + boost::shared_ptr< ConfigurationChanges > const & batch, + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + detail::ConfigurationWrapper::get(context).setPropertyValue( + batch, T::path(), detail::Convert< U >::toAny(value)); + } + +private: + ConfigurationProperty(); // not defined + ~ConfigurationProperty(); // not defined +}; + +/// A type-safe wrapper around a localized configuration property. +/// +/// Automatically generated headers for the various localized configuration +/// properties derive from this template and make available its member functions +/// to access each given localized configuration property. +template< typename T, typename U > struct ConfigurationLocalizedProperty: + private boost::noncopyable +{ + /// Get the value of the given localized configuration property, for the + /// locale currently set at the + /// com.sun.star.configuration.theDefaultProvider. + /// + /// For nillable properties, U is of type boost::optional<U'>. + static U get( + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + // Folding this into one statement causes a bogus error at least with + // Red Hat GCC 4.6.2-1: + com::sun::star::uno::Any a( + detail::ConfigurationWrapper::get(context). + getLocalizedPropertyValue(T::path())); + return detail::Convert< U >::fromAny(a); + } + + /// Set the value of the given localized configuration property, for the + /// locale currently set at the + /// com.sun.star.configuration.theDefaultProvider, via a given changes + /// batch. + /// + /// For nillable properties, U is of type boost::optional<U'>. + static void set( + U const & value, + boost::shared_ptr< ConfigurationChanges > const & batch, + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + detail::ConfigurationWrapper::get(context).setLocalizedPropertyValue( + batch, T::path(), detail::Convert< U >::toAny(value)); + } + +private: + ConfigurationLocalizedProperty(); // not defined + ~ConfigurationLocalizedProperty(); // not defined +}; + +/// A type-safe wrapper around a configuration group. +/// +/// Automatically generated headers for the various configuration groups derive +/// from this template and make available its member functions to access each +/// given configuration group. +template< typename T > struct ConfigurationGroup: private boost::noncopyable { + /// Get read-only access to the given configuration group. + static com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > + get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + return detail::ConfigurationWrapper::get(context).getGroupReadOnly( + T::path()); + } + + /// Get read/write access to the given configuration group, storing any + /// modifications via the given changes batch. + static com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameReplace > + get(boost::shared_ptr< ConfigurationChanges > const & batch, + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + return detail::ConfigurationWrapper::get(context).getGroupReadWrite( + batch, T::path()); + } + +private: + ConfigurationGroup(); // not defined + ~ConfigurationGroup(); // not defined +}; + +/// A type-safe wrapper around a configuration set. +/// +/// Automatically generated headers for the various configuration sets derive +/// from this template and make available its member functions to access each +/// given configuration set. +template< typename T > struct ConfigurationSet: private boost::noncopyable { + /// Get read-only access to the given configuration set. + static + com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > + get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + return detail::ConfigurationWrapper::get(context).getSetReadOnly( + T::path()); + } + + /// Get read/write access to the given configuration set, storing any + /// modifications via the given changes batch. + static + com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > + get(boost::shared_ptr< ConfigurationChanges > const & batch, + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context = comphelper::getProcessComponentContext()) + { + return detail::ConfigurationWrapper::get(context).getSetReadWrite( + batch, T::path()); + } + +private: + ConfigurationSet(); // not defined + ~ConfigurationSet(); // not defined +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/configurationhelper.hxx b/include/comphelper/configurationhelper.hxx new file mode 100644 index 000000000000..b267e4c0c564 --- /dev/null +++ b/include/comphelper/configurationhelper.hxx @@ -0,0 +1,240 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_ +#define _COMPHELPER_CONFIGURATIONHELPER_HXX_ + +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> +#include <comphelper/sequenceasvector.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include "comphelper/comphelperdllapi.h" + +//_______________________________________________ +// namespaces + +namespace comphelper{ + + +//----------------------------------------------- +class COMPHELPER_DLLPUBLIC ConfigurationHelper +{ + public: + + //----------------------------------------------- + /** specify all possible modes, which can be used to open a configuration access. + * + * @see openConfig() + * @see readDirectKey() + * @see writeDirectKey() + */ + enum EConfigurationModes + { + /// opens configuration in read/write mode (without LAZY writing!) + E_STANDARD = 0, + /// configuration will be opened readonly + E_READONLY = 1, + /// all localized nodes will be interpreted as XInterface instead of interpreting it as atomic value nodes + E_ALL_LOCALES = 2, + /// enable lazy writing + E_LAZY_WRITE = 4 + }; + + //----------------------------------------------- + /** returns access to the specified configuration package. + * + * This method should be used, if e.g. more then one request to the same + * configuration package is needed. The configuration access can be cached + * outside and used inbetween. + * + * @param rxContext + * the uno service manager, which should be used to create the + * configuration access. + * + * @param sPackage + * the name of the configuration package. + * e.g. <ul> + * <li>org.openoffice.Office.Common</li> + * <li>org.openoffice.Office.Common/Menu</li> + * </ul> + * + * @param eMode + * specify the open mode for the returned configuration access. + * It's interpreted as a flag field and can be any useful combination + * of values of EConfigurationModes. + * + * @throw Any exceptions the underlying configuration can throw. + * E.g. css::uno::Exception if the configuration could not be opened. + */ + static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const OUString& sPackage, + sal_Int32 eMode ); + + //----------------------------------------------- + /** reads the value of an existing(!) configuration key, + * which is searched relative to the specified configuration access. + * + * This method must be used in combination with openConfig(). + * The cached configuration access must be provided here ... and + * all operations are made relativ to this access point. + * + * @param xCFG + * the configuration root, where sRelPath should be interpreted. + * as relativ path + * + * @param sRelPath + * path relative to xCFG parameter. + * + * @param sKey + * the configuration node, where we should read the value. + * + * @return [css.uno.Any] + * the value of sKey. + * + * @throw Any exceptions the underlying configuration can throw. + * E.g. css::container::NoSuchElementException if the specified + * key does not exists. + */ + static css::uno::Any readRelativeKey(const css::uno::Reference< css::uno::XInterface > xCFG , + const OUString& sRelPath, + const OUString& sKey ); + + //----------------------------------------------- + /** writes a new value for an existing(!) configuration key, + * which is searched relative to the specified configuration access. + * + * This method must be used in combination with openConfig(). + * The cached configuration access must be provided here ... and + * all operations are made relativ to this access point. + * + * @param xCFG + * the configuration root, where sRelPath should be interpreted. + * as relativ path + * + * @param sRelPath + * path relative to xCFG parameter. + * + * @param sKey + * the configuration node, where we should write the new value. + * + * @param aValue + * the new value for sKey. + * + * @throw Any exceptions the underlying configuration can throw. + * E.g. css::container::NoSuchElementException if the specified + * key does not exists or css::uno::Exception if the provided configuration + * access does not allow writing for this key. + */ + static void writeRelativeKey(const css::uno::Reference< css::uno::XInterface > xCFG , + const OUString& sRelPath, + const OUString& sKey , + const css::uno::Any& aValue ); + + //----------------------------------------------- + /** it checks if the specified set node exists ... or create an empty one + * otherwise. + * + * This method must be used in combination with openConfig(). + * The cached configuration access must be provided here ... and + * all operations are made relativ to this access point. + * + * Further this method must be used only with configuration set's. + * Atomic keys can't be "created" ... they "exists everytimes". + * + * @param xCFG + * the configuration root, where sRelPathToSet should be interpreted + * as relativ path. + * + * @param sRelPathToSet + * path relative to xCFG parameter. + * + * @param sSetNode + * the set node, which should be checked if its exists ... + * or which should be created with default values. + * + * @return A reference to the found (or new created) set node. + * Cant be NULL .. in such case an exception occure ! + * + * @throw Any exceptions the underlying configuration can throw. + * E.g. css::uno::Exception if the provided configuration + * access does not allow writing for this set. + */ + static css::uno::Reference< css::uno::XInterface > makeSureSetNodeExists(const css::uno::Reference< css::uno::XInterface > xCFG , + const OUString& sRelPathToSet, + const OUString& sSetNode ); + + //----------------------------------------------- + /** commit all changes made on the specified configuration access. + * + * This method must be used in combination with openConfig(). + * The cached configuration access must be provided here. + * + * @param xCFG + * the configuration root, where changes should be commited. + * + * @throw Any exceptions the underlying configuration can throw. + * E.g. css::uno::Exception if the provided configuration + * access does not allow writing for this set. + */ + static void flush(const css::uno::Reference< css::uno::XInterface >& xCFG); + + //----------------------------------------------- + /** does the same then openConfig() & readRelativeKey() together. + * + * This method should be used for reading one key at one code place only. + * Because it opens the specified configuration package, reads the key and + * closes the configuration again. + * + * So its not very useful to use this method for reading multiple keys at the same time. + * (Excepting these keys exists inside different configuration packages ...)) + */ + static css::uno::Any readDirectKey(const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const OUString& sPackage, + const OUString& sRelPath, + const OUString& sKey , + sal_Int32 eMode ); + + //----------------------------------------------- + /** does the same then openConfig() / writeRelativeKey() & flush() together. + * + * This method should be used for writing one key at one code place only. + * Because it opens the specified configuration package, writes the key, flush + * all changes and closes the configuration again. + * + * So its not very useful to use this method for writing multiple keys at the same time. + * (Excepting these keys exists inside different configuration packages ...)) + */ + static void writeDirectKey(const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const OUString& sPackage, + const OUString& sRelPath, + const OUString& sKey , + const css::uno::Any& aValue , + sal_Int32 eMode ); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_CONFIGURATIONHELPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/container.hxx b/include/comphelper/container.hxx new file mode 100644 index 000000000000..d6c5be927873 --- /dev/null +++ b/include/comphelper/container.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_CONTAINER_HXX_ +#define _COMPHELPER_CONTAINER_HXX_ + +#include <vector> +#include "com/sun/star/uno/Reference.hxx" +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//======================================================================== +//= IndexAccessIterator +//======================================================================== +/** an iterator that iterates through all elements, starting from an XIndexAccess (pre-order) +*/ +class COMPHELPER_DLLPUBLIC IndexAccessIterator +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> m_xStartingPoint; + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> m_xCurrentObject; + // The current object + ::std::vector<sal_Int32> m_arrChildIndizies; + + // I'm moving through a tree, but its elements have no GetNextSibling, + // so I have to remember where each child is in relation to its parent. + // That is the path from the root node to m_xCurrentObject + + OUString m_ustrProperty; + // The Name of the requested property + +public: + IndexAccessIterator(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xStartingPoint); + + virtual ~IndexAccessIterator(); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> Next(); + + virtual void Invalidate() { m_xCurrentObject = NULL; } + +protected: + virtual sal_Bool ShouldHandleElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& /*rElement*/) { return sal_True; } + + // This can be used to exclude certain elements; elements for which + // this function returns sal_True will be simply skipped. + // If this element is returned from Next(), then one can get + // here get a little more information on the element. + // That's why this method is not const. + virtual sal_Bool ShouldStepInto(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& /*xContainer*/) const { return sal_True; } +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_CONTAINER_HXX_ + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/containermultiplexer.hxx b/include/comphelper/containermultiplexer.hxx new file mode 100644 index 000000000000..725265e493c6 --- /dev/null +++ b/include/comphelper/containermultiplexer.hxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_CONTAINERMULTIPLEXER_HXX_ +#define _COMPHELPER_CONTAINERMULTIPLEXER_HXX_ + +#include <com/sun/star/container/XContainer.hpp> +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + class OContainerListenerAdapter; + //===================================================================== + //= OContainerListener + //===================================================================== + /** a non-UNO container listener + <p>Useful if you have a non-refcountable class which should act as container listener.<br/> + In this case, derive this class from OContainerListener, and create an adapter + <type>OContainerListenerAdapter</type> which multiplexes the changes.</p> + */ + class COMPHELPER_DLLPUBLIC OContainerListener + { + friend class OContainerListenerAdapter; + protected: + OContainerListenerAdapter* m_pAdapter; + ::osl::Mutex& m_rMutex; + + public: + OContainerListener(::osl::Mutex& _rMutex); + virtual ~OContainerListener(); + + virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); + virtual void _elementRemoved( const ::com::sun::star::container::ContainerEvent& _Event ) throw(::com::sun::star::uno::RuntimeException); + virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); + virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException); + + protected: + void setAdapter(OContainerListenerAdapter* _pAdapter); + }; + + //===================================================================== + //= OContainerListenerAdapter + //===================================================================== + class COMPHELPER_DLLPUBLIC OContainerListenerAdapter + :public cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener > + { + friend class OContainerListener; + + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer > + m_xContainer; + OContainerListener* m_pListener; + sal_Int32 m_nLockCount; + + virtual ~OContainerListenerAdapter(); + + public: + OContainerListenerAdapter(OContainerListener* _pListener, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _rxContainer); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException); + + // XContainerListener + virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); + + // locking the multiplexer + sal_Int32 locked() const { return m_nLockCount; } + + /// dispose the object. No multiplexing anymore + void dispose(); + + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& + getContainer() const { return m_xContainer; } + }; + +//......................................................................... +} // namespace dbaui +//......................................................................... + +#endif // _COMPHELPER_CONTAINERMULTIPLEXER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/docpasswordhelper.hxx b/include/comphelper/docpasswordhelper.hxx new file mode 100644 index 000000000000..24fd868c0735 --- /dev/null +++ b/include/comphelper/docpasswordhelper.hxx @@ -0,0 +1,353 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_DOCPASSWORDHELPR_HXX +#define COMPHELPER_DOCPASSWORDHELPR_HXX + +#include <com/sun/star/beans/NamedValue.hpp> +#include "comphelper/comphelperdllapi.h" +#include <vector> +#include "comphelper/docpasswordrequest.hxx" + +namespace com { namespace sun { namespace star { namespace task { class XInteractionHandler; } } } } +namespace com { namespace sun { namespace star { namespace beans { struct PropertyValue; } } } } + +namespace comphelper { + +class MediaDescriptor; + +// ============================================================================ + +enum DocPasswordVerifierResult +{ + DocPasswordVerifierResult_OK, + DocPasswordVerifierResult_WRONG_PASSWORD, + DocPasswordVerifierResult_ABORT +}; + +// ============================================================================ + +/** Base class for a password verifier used by the DocPasswordHelper class + below. + + Users have to implement the virtual functions and pass an instance of the + verifier to one of the password request functions. + */ +class COMPHELPER_DLLPUBLIC IDocPasswordVerifier +{ +public: + virtual ~IDocPasswordVerifier(); + + /** Will be called everytime a password needs to be verified. + + @param rPassword + The password to be verified + + @param o_rEncryptionData + Output parameter, that is filled with the EncryptionData generated + from the password. The data is filled only if the validation was + successful. + + @return The result of the verification. + - DocPasswordVerifierResult_OK, if and only if the passed password + is valid and can be used to process the related document. + - DocPasswordVerifierResult_WRONG_PASSWORD, if the password is + wrong. The user may be asked again for a new password. + - DocPasswordVerifierResult_ABORT, if an unrecoverable error + occurred while password verification. The password request loop + will be aborted. + */ + virtual DocPasswordVerifierResult verifyPassword( const OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) = 0; + + /** Will be called everytime an encryption data needs to be verified. + + @param rEncryptionData + The data will be validated + + @return The result of the verification. + - DocPasswordVerifierResult_OK, if and only if the passed encryption data + is valid and can be used to process the related document. + - DocPasswordVerifierResult_WRONG_PASSWORD, if the encryption data is + wrong. + - DocPasswordVerifierResult_ABORT, if an unrecoverable error + occured while data verification. The password request loop + will be aborted. + */ + virtual DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) = 0; + +}; + +// ============================================================================ + +/** Helper that asks for a document password and checks its validity. + */ +class COMPHELPER_DLLPUBLIC DocPasswordHelper +{ +public: + // ------------------------------------------------------------------------ + + /** This helper function generates the information related + to "Password to modify" provided by user. The result + sequence contains the hash and the algorithm-related + info. + + @param aString + The string for which the info should be generated + + @return + The sequence containing the hash and the algorithm-related info + */ + + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + GenerateNewModifyPasswordInfo( const OUString& aPassword ); + + // ------------------------------------------------------------------------ + + /** This helper function allows to check whether + the "Password to modify" provided by user is the correct one. + + @param aString + The string containing the provided password + + @param aInfo + The sequence containing the hash and the algorithm-info + + @return + <TRUE/> if the password is correct one + <FALSE/> otherwise + */ + + static sal_Bool IsModifyPasswordCorrect( + const OUString& aPassword, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aInfo ); + + + // ------------------------------------------------------------------------ + + /** This helper function generates the hash code based on the algorithm + specified by MS for "Password to modify" feature of Word. + + @param aString + The string for which the hash should be calculated + + @return + The hash represented by sal_uInt32 + */ + + static sal_uInt32 GetWordHashAsUINT32( + const OUString& aString ); + + // ------------------------------------------------------------------------ + + /** This helper function generates the hash code based on the algorithm + specified by MS for "Password to modify" and passwords related to + table protection of Excel. + + @param aString + The string for which the hash should be calculated + + @param nEnc + The encoding that should be used to generate the 8-bit string + before the hash is generated + + @return + The hash represented by sal_uInt16 + */ + + static sal_uInt16 GetXLHashAsUINT16( + const OUString& aString, + rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 ); + + // ------------------------------------------------------------------------ + + /** This helper function generates the hash code based on the algorithm + specified by MS for "Password to modify" and passwords related to + table protection. + + @param aString + The string for which the hash should be calculated + + @param nEnc + The encoding that should be used to generate the 8-bit string + before the hash is generated + + @return + The hash represented by sequence of bytes in BigEndian form + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GetXLHashAsSequence( + const OUString& aString, + rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 ); + + // ------------------------------------------------------------------------ + + /** This helper function generates a random sequence of bytes of + requested length. + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateRandomByteSequence( + sal_Int32 nLength ); + + // ------------------------------------------------------------------------ + + /** This helper function generates a byte sequence representing the + key digest value used by MSCodec_Std97 codec. + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateStd97Key( + const OUString& aPassword, + const ::com::sun::star::uno::Sequence< sal_Int8 >& aDocId ); + + // ------------------------------------------------------------------------ + + /** This helper function generates a byte sequence representing the + key digest value used by MSCodec_Std97 codec. + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateStd97Key( + const sal_uInt16 pPassData[16], + const ::com::sun::star::uno::Sequence< sal_Int8 >& aDocId ); + + // ------------------------------------------------------------------------ + + /** This helper function tries to request and verify a password to load a + protected document. + + First, the list of default passwords will be tried if provided. This is + needed by import filters for external file formats that have to check a + predefined password in some cases without asking the user for a + password. Every password is checked using the passed password verifier. + + If not successful, the passed password of a medium is tried, that has + been set e.g. by an API call to load a document. If existing, the + password is checked using the passed password verifier. + + If still not successful, the passed interaction handler is used to + request a password from the user. This will be repeated until the + passed password verifier validates the entered password, or if the user + chooses to cancel password input. + + @param rVerifier + The password verifier used to check every processed password. + + @param rMediaPassword + If not empty, will be passed to the password validator before + requesting a password from the user. This password usually should + be querried from a media descriptor. + + @param rxInteractHandler + The interaction handler that will be used to request a password + from the user, e.g. by showing a password input dialog. + + @param rDocumentName + The name of the related document that will be shown in the password + input dialog. + + @param eRequestType + The password request type that will be passed to the + DocPasswordRequest object created internally. See + docpasswordrequest.hxx for more details. + + @param pDefaultPasswords + If not null, contains default passwords that will be tried before a + password will be requested from the media descriptor or the user. + + @param pbIsDefaultPassword + (output parameter) If not null, the type of the found password will + be returned. True means the password has been found in the passed + list of default passwords. False means the password has been taken + from the rMediaPassword parameter or has been entered by the user. + + @return + If not empty, contains the password that has been validated by the + passed password verifier. If empty, no valid password has been + found, or the user has chossen to cancel password input. + */ + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rMediaEncData, + const OUString& rMediaPassword, + const ::com::sun::star::uno::Reference< + ::com::sun::star::task::XInteractionHandler >& rxInteractHandler, + const OUString& rDocumentName, + DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords = 0, + bool* pbIsDefaultPassword = 0 ); + + // ------------------------------------------------------------------------ + + /** This helper function tries to find a password for the document + described by the passed media descriptor. + + First, the list of default passwords will be tried if provided. This is + needed by import filters for external file formats that have to check a + predefined password in some cases without asking the user for a + password. Every password is checked using the passed password verifier. + + If not successful, the passed media descriptor is asked for a password, + that has been set e.g. by an API call to load a document. If existing, + the password is checked using the passed password verifier. + + If still not successful, the interaction handler contained in the + passed nmedia descriptor is used to request a password from the user. + This will be repeated until the passed password verifier validates the + entered password, or if the user chooses to cancel password input. + + @param rVerifier + The password verifier used to check every processed password. + + @param rMediaDesc + The media descriptor of the document that needs to be opened with + a password. If a valid password (that is not contained in the + passed list of default passwords) was found, it will be inserted + into the "Password" property of this descriptor. + + @param eRequestType + The password request type that will be passed to the + DocPasswordRequest object created internally. See + docpasswordrequest.hxx for more details. + + @param pDefaultPasswords + If not null, contains default passwords that will be tried before a + password will be requested from the media descriptor or the user. + + @return + If not empty, contains the password that has been validated by the + passed password verifier. If empty, no valid password has been + found, or the user has chossen to cancel password input. + */ + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + MediaDescriptor& rMediaDesc, + DocPasswordRequestType eRequestType, + const ::std::vector< OUString >* pDefaultPasswords = 0 ); + + // ------------------------------------------------------------------------ + +private: + ~DocPasswordHelper(); +}; + +// ============================================================================ + +} // namespace comphelper + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/docpasswordrequest.hxx b/include/comphelper/docpasswordrequest.hxx new file mode 100644 index 000000000000..54a32f522ae6 --- /dev/null +++ b/include/comphelper/docpasswordrequest.hxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_DOCPASSWORDREQUEST_HXX +#define COMPHELPER_DOCPASSWORDREQUEST_HXX + +#include "comphelper/comphelperdllapi.h" +#include <com/sun/star/task/PasswordRequestMode.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/weak.hxx> + + +namespace comphelper { + +class AbortContinuation; +class PasswordContinuation; + +// ============================================================================ + +/** Selects which UNO document password request type to use. */ +enum DocPasswordRequestType +{ + DocPasswordRequestType_STANDARD, /// Uses the standard com.sun.star.task.DocumentPasswordRequest request. + DocPasswordRequestType_MS /// Uses the com.sun.star.task.DocumentMSPasswordRequest request. +}; + +// ============================================================================ + +class COMPHELPER_DLLPUBLIC SimplePasswordRequest : + public ::com::sun::star::task::XInteractionRequest, + public ::cppu::OWeakObject +{ +public: + explicit SimplePasswordRequest( com::sun::star::task::PasswordRequestMode eMode ); + virtual ~SimplePasswordRequest(); + + // XInterface / OWeakObject + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire( ) throw (); + virtual void SAL_CALL release( ) throw (); + + sal_Bool isPassword() const; + + OUString getPassword() const; + +private: + // XInteractionRequest + virtual ::com::sun::star::uno::Any SAL_CALL getRequest() throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations() throw( ::com::sun::star::uno::RuntimeException ); + +private: + ::com::sun::star::uno::Any maRequest; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > maContinuations; + AbortContinuation * mpAbort; + PasswordContinuation * mpPassword; +}; + +// ============================================================================ + +/** Implements the task.XInteractionRequest interface for requesting a password + string for a document. + */ +class COMPHELPER_DLLPUBLIC DocPasswordRequest : + public ::com::sun::star::task::XInteractionRequest, + public ::cppu::OWeakObject +{ +public: + explicit DocPasswordRequest( + DocPasswordRequestType eType, + ::com::sun::star::task::PasswordRequestMode eMode, + const OUString& rDocumentName, + sal_Bool bPasswordToModify = sal_False ); + virtual ~DocPasswordRequest(); + + // XInterface / OWeakObject + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire( ) throw (); + virtual void SAL_CALL release( ) throw (); + + sal_Bool isPassword() const; + + OUString getPassword() const; + + OUString getPasswordToModify() const; + sal_Bool getRecommendReadOnly() const; + +private: + // XInteractionRequest + virtual ::com::sun::star::uno::Any SAL_CALL getRequest() throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations() throw( ::com::sun::star::uno::RuntimeException ); + +private: + ::com::sun::star::uno::Any maRequest; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > maContinuations; + AbortContinuation * mpAbort; + PasswordContinuation * mpPassword; +}; + +// ============================================================================ + +} // namespace comphelper + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/documentconstants.hxx b/include/comphelper/documentconstants.hxx new file mode 100644 index 000000000000..2bc00220995f --- /dev/null +++ b/include/comphelper/documentconstants.hxx @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_DOCUMENTCONSTANTS_HXX +#define _COMPHELPER_DOCUMENTCONSTANTS_HXX + +#include <rtl/ustring.hxx> + +// formats of SO6/7 +#define MIMETYPE_VND_SUN_XML_WRITER_ASCII "application/vnd.sun.xml.writer" +#define MIMETYPE_VND_SUN_XML_WRITER_WEB_ASCII "application/vnd.sun.xml.writer.web" +#define MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII "application/vnd.sun.xml.writer.global" +#define MIMETYPE_VND_SUN_XML_DRAW_ASCII "application/vnd.sun.xml.draw" +#define MIMETYPE_VND_SUN_XML_IMPRESS_ASCII "application/vnd.sun.xml.impress" +#define MIMETYPE_VND_SUN_XML_CALC_ASCII "application/vnd.sun.xml.calc" +#define MIMETYPE_VND_SUN_XML_CHART_ASCII "application/vnd.sun.xml.chart" +#define MIMETYPE_VND_SUN_XML_MATH_ASCII "application/vnd.sun.xml.math" +#define MIMETYPE_VND_SUN_XML_BASE_ASCII "application/vnd.sun.xml.base" + +#define MIMETYPE_VND_SUN_XML_WRITER OUString( MIMETYPE_VND_SUN_XML_WRITER_ASCII ) +#define MIMETYPE_VND_SUN_XML_WRITER_WEB OUString( MIMETYPE_VND_SUN_XML_WRITER_WEB_ASCII ) +#define MIMETYPE_VND_SUN_XML_WRITER_GLOBAL OUString( MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII ) +#define MIMETYPE_VND_SUN_XML_DRAW OUString( MIMETYPE_VND_SUN_XML_DRAW_ASCII ) +#define MIMETYPE_VND_SUN_XML_IMPRESS OUString( MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) +#define MIMETYPE_VND_SUN_XML_CALC OUString( MIMETYPE_VND_SUN_XML_CALC_ASCII ) +#define MIMETYPE_VND_SUN_XML_CHART OUString( MIMETYPE_VND_SUN_XML_CHART_ASCII ) +#define MIMETYPE_VND_SUN_XML_MATH OUString( MIMETYPE_VND_SUN_XML_MATH_ASCII ) +#define MIMETYPE_VND_SUN_XML_BASE OUString( MIMETYPE_VND_SUN_XML_BASE_ASCII ) + +// template formats of SO6/7 +#define MIMETYPE_VND_SUN_XML_WRITER_TEMPLATE_ASCII "application/vnd.sun.xml.writer.template" +#define MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE_ASCII "application/vnd.sun.xml.draw.template" +#define MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE_ASCII "application/vnd.sun.xml.impress.template" +#define MIMETYPE_VND_SUN_XML_CALC_TEMPLATE_ASCII "application/vnd.sun.xml.calc.template" + +#define MIMETYPE_VND_SUN_XML_WRITER_TEMPLATE OUString( MIMETYPE_VND_SUN_XML_WRITER_ASCII ) +#define MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE OUString( MIMETYPE_VND_SUN_XML_DRAW_ASCII ) +#define MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE OUString( MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) +#define MIMETYPE_VND_SUN_XML_CALC_TEMPLATE OUString( MIMETYPE_VND_SUN_XML_CALC_ASCII ) + +// formats of SO8 +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII "application/vnd.oasis.opendocument.text" +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII "application/vnd.oasis.opendocument.text-web" +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII "application/vnd.oasis.opendocument.text-master" +#define MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII "application/vnd.oasis.opendocument.graphics" +#define MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII "application/vnd.oasis.opendocument.presentation" +#define MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII "application/vnd.oasis.opendocument.spreadsheet" +#define MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII "application/vnd.oasis.opendocument.chart" +#define MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII "application/vnd.oasis.opendocument.formula" +#define MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII "application/vnd.oasis.opendocument.base" +#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII "application/vnd.sun.xml.report" +#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII "application/vnd.sun.xml.report.chart" + +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT OUString( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB OUString( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL OUString( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_DRAWING OUString( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION OUString( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET OUString( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_CHART OUString( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_FORMULA OUString( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_DATABASE OUString( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT OUString( MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART OUString( MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII ) + +// template formats of SO8 +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII "application/vnd.oasis.opendocument.text-template" +#define MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII "application/vnd.oasis.opendocument.graphics-template" +#define MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII "application/vnd.oasis.opendocument.presentation-template" +#define MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII "application/vnd.oasis.opendocument.spreadsheet-template" +#define MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII "application/vnd.oasis.opendocument.chart-template" +#define MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII "application/vnd.oasis.opendocument.formula-template" + +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE OUString( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE OUString( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE OUString( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE OUString( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE OUString( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) +#define MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE OUString( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) + +// ODF versions +#define ODFVER_010_TEXT_ASCII "1.0" +#define ODFVER_011_TEXT_ASCII "1.1" +#define ODFVER_012_TEXT_ASCII "1.2" + +#define ODFVER_010_TEXT OUString( ODFVER_010_TEXT_ASCII ) +#define ODFVER_011_TEXT OUString( ODFVER_011_TEXT_ASCII ) +#define ODFVER_012_TEXT OUString( ODFVER_012_TEXT_ASCII ) +#endif + +// filter flags +// TODO/LATER: The flags should be part of the UNO specification + +// Note that these flag bits have parallel names in +// filter/source/config/cache/constant.hxx. Some of the bits are +// missing from there, and some have different names. But the meaning +// is presumably the same, and the values are the same. + +// http://www.mail-archive.com/dev@openoffice.org/msg05047.html says: + +// I can just sum up what comes into my mind, hope I don't miss one: + +// Import - should be self explaining +// Export - should be self explaining +// Template - deprecated +// TemplatePath - filter for a documenttemplate +// Own - one of the OOo file formats +// Alien - no zip container based format +// Preferred - preferred filter for a particular type +// Asynchron - deprecated, only HTML-filter isn't synchron +// 3rdPartyFilter - implemented as a UNO component +// Default - default filter for this document type +// NotInFileDialog - should be self explaining +// NotInChooser - as above + +// (The 3rdPartyFilter flag is here called StarONE) + +// At some point (4.0?) we should drop the duplicate set of names over +// in filter, and rename the obscure ones to describe their meaning +// using terms that are understandable. + +#define SFX_FILTER_IMPORT 0x00000001L +#define SFX_FILTER_EXPORT 0x00000002L +#define SFX_FILTER_TEMPLATE 0x00000004L +#define SFX_FILTER_INTERNAL 0x00000008L +#define SFX_FILTER_TEMPLATEPATH 0x00000010L +#define SFX_FILTER_OWN 0x00000020L +#define SFX_FILTER_ALIEN 0x00000040L +#define SFX_FILTER_USESOPTIONS 0x00000080L + +#define SFX_FILTER_DEFAULT 0x00000100L +#define SFX_FILTER_EXECUTABLE 0x00000200L +#define SFX_FILTER_SUPPORTSSELECTION 0x00000400L +#define SFX_FILTER_MAPTOAPPPLUG 0x00000800L +#define SFX_FILTER_NOTINFILEDLG 0x00001000L +#define SFX_FILTER_NOTINCHOOSER 0x00002000L +#define SFX_FILTER_ASYNC 0x00004000L +#define SFX_FILTER_CREATOR 0x00008000L +#define SFX_FILTER_OPENREADONLY 0x00010000L +#define SFX_FILTER_MUSTINSTALL 0x00020000L +#define SFX_FILTER_CONSULTSERVICE 0x00040000L + +#define SFX_FILTER_STARONEFILTER 0x00080000L +#define SFX_FILTER_PACKED 0x00100000L + +#define SFX_FILTER_BROWSERPREFERED 0x00400000L + +#define SFX_FILTER_ENCRYPTION 0x01000000L +#define SFX_FILTER_PASSWORDTOMODIFY 0x02000000L + +#define SFX_FILTER_PREFERED 0x10000000L + +#define SFX_FILTER_VERSION_NONE 0 +#define SFX_FILTER_NOTINSTALLED SFX_FILTER_MUSTINSTALL | SFX_FILTER_CONSULTSERVICE + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/documentinfo.hxx b/include/comphelper/documentinfo.hxx new file mode 100644 index 000000000000..48bc39a8cc00 --- /dev/null +++ b/include/comphelper/documentinfo.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_DOCUMENTINFO_HXX +#define COMPHELPER_DOCUMENTINFO_HXX + +#include "comphelper/comphelperdllapi.h" + +#include <com/sun/star/frame/XModel.hpp> + +//........................................................................ +namespace comphelper { +//........................................................................ + + //==================================================================== + //= DocumentInfo + //==================================================================== + class COMPHELPER_DLLPUBLIC DocumentInfo + { + public: + /** retrieves the UI title of the given document + */ + static OUString getDocumentTitle( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument ); + + private: + DocumentInfo(); // never implemented + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_DOCUMENTINFO_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/embeddedobjectcontainer.hxx b/include/comphelper/embeddedobjectcontainer.hxx new file mode 100644 index 000000000000..0347e12ba2c2 --- /dev/null +++ b/include/comphelper/embeddedobjectcontainer.hxx @@ -0,0 +1,181 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_OBJECTCONTAINER_HXX_ +#define _COMPHELPER_OBJECTCONTAINER_HXX_ + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/embed/XEmbeddedObject.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include "comphelper/comphelperdllapi.h" + +#include <rtl/ustring.hxx> + +namespace comphelper +{ + class EmbeddedObjectContainer; + /** Helper interface to give access to some common object which replace the SfxObjectShell + */ + class SAL_NO_VTABLE IEmbeddedHelper + { + public: + virtual EmbeddedObjectContainer& getEmbeddedObjectContainer() const = 0; + virtual com::sun::star::uno::Reference < com::sun::star::embed::XStorage > getStorage() const = 0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > getInteractionHandler() const = 0; + virtual bool isEnableSetModified() const = 0; + + protected: + ~IEmbeddedHelper() {} + }; + +struct EmbedImpl; +class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer +{ + EmbedImpl* pImpl; + + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > Get_Impl( const OUString&, + const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xCopy); + +public: + // add an embedded object to the container storage + sal_Bool StoreEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString&, sal_Bool ); + + // add an embedded object that has been imported from the container storage - should only be called by filters! + void AddEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, const OUString& ); + + EmbeddedObjectContainer(); + EmbeddedObjectContainer( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& ); + EmbeddedObjectContainer( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&, + const com::sun::star::uno::Reference < com::sun::star::uno::XInterface >& ); + ~EmbeddedObjectContainer(); + + void SwitchPersistence( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& ); + sal_Bool CommitImageSubStorage(); + void ReleaseImageSubStorage(); + + OUString CreateUniqueObjectName(); + + // get a list of object names that have been added so far + com::sun::star::uno::Sequence < OUString > GetObjectNames(); + + // check for existence of objects at all + sal_Bool HasEmbeddedObjects(); + + // check existence of an object - either by identity or by name + sal_Bool HasEmbeddedObject( const OUString& ); + sal_Bool HasEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& ); + sal_Bool HasInstantiatedEmbeddedObject( const OUString& ); + + // get the object name of an object - this is the persist name if the object has persistence + OUString GetEmbeddedObjectName( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& ); + + // retrieve an embedded object by name that either has been added already or is available in the container storage + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > GetEmbeddedObject( const OUString& ); + + // create an object from a ClassId + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > + CreateEmbeddedObject( const com::sun::star::uno::Sequence < sal_Int8 >&, OUString& ); + + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > + CreateEmbeddedObject( const com::sun::star::uno::Sequence < sal_Int8 >&, + const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >&, OUString& ); + + // insert an embedded object into the container - objects persistent representation will be added to the storage + sal_Bool InsertEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString& ); + + // load an embedded object from a MediaDescriptor and insert it into the container + // a new object will be created from the new content and returned + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > + InsertEmbeddedObject( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, OUString& ); + + // create an embedded link based on a MediaDescriptor and insert it into the container + // a new object will be created from the new content and returned + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > + InsertEmbeddedLink( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, OUString& ); + + // create an object from a stream that contains its persistent representation and insert it as usual (usually called from clipboard) + // a new object will be created from the new content and returned + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > + InsertEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >&, OUString& ); + + // copy an embedded object into the storage, open the new copy and return it + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > CopyAndGetEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xObj, /* TODO const OUString& aOrigName,*/ OUString& rName ); + + // move an embedded object from one container to another one + sal_Bool MoveEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString& ); + + // remove an embedded object from the container and from the storage; if object can't be closed + sal_Bool RemoveEmbeddedObject( const OUString& rName, sal_Bool bClose=sal_True ); + sal_Bool RemoveEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, sal_Bool bClose=sal_True ); + + // close and remove an embedded object from the container without removing it from the storage + sal_Bool CloseEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& ); + + // move an embedded object to another container (keep the persistent name) + sal_Bool MoveEmbeddedObject( const OUString& rName, EmbeddedObjectContainer& ); + + // get the stored graphical representation for the object + com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetGraphicStream( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString* pMediaType=0 ); + + // get the stored graphical representation by the object name + com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetGraphicStream( const OUString& aName, OUString* pMediaType=0 ); + + // add a graphical representation for an object + sal_Bool InsertGraphicStream( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream, const OUString& rObjectName, const OUString& rMediaType ); + + // try to add a graphical representation for an object in optimized way ( might fail ) + sal_Bool InsertGraphicStreamDirectly( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream, const OUString& rObjectName, const OUString& rMediaType ); + + // remove a graphical representation for an object + sal_Bool RemoveGraphicStream( const OUString& rObjectName ); + + // copy the graphical representation from different container + sal_Bool TryToCopyGraphReplacement( EmbeddedObjectContainer& rSrc, + const OUString& aOrigName, + const OUString& aTargetName ); + + void CloseEmbeddedObjects(); + sal_Bool StoreChildren(sal_Bool _bOasisFormat,sal_Bool _bObjectsOnly); + sal_Bool StoreAsChildren( sal_Bool _bOasisFormat + ,sal_Bool _bCreateEmbedded + ,const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& _xStorage); + + static com::sun::star::uno::Reference< com::sun::star::io::XInputStream > GetGraphicReplacementStream( + sal_Int64 nViewAspect, + const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >&, + OUString* pMediaType ); + + /** call setPersistentEntry for each embedded object in the container + * + * \param _xStorage The storeage where to store the objects. + * \param _bClearModifedFlag If <TRUE/> then the modifed flag will be set to <FALSE/> otherwise nothing happen. + * \return <FALSE/> if no error occurred, otherwise <TRUE/>. + */ + sal_Bool SetPersistentEntries(const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& _xStorage,bool _bClearModifedFlag = true); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/enumhelper.hxx b/include/comphelper/enumhelper.hxx new file mode 100644 index 000000000000..9870291b22f5 --- /dev/null +++ b/include/comphelper/enumhelper.hxx @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_ENUMHELPER_HXX_ +#define _COMPHELPER_ENUMHELPER_HXX_ + +#include <vector> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <osl/mutex.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace starcontainer = ::com::sun::star::container; + namespace staruno = ::com::sun::star::uno; + namespace starlang = ::com::sun::star::lang; + +//================================================================== +//= OEnumerationLock +//================================================================== +struct OEnumerationLock +{ + public: + ::osl::Mutex m_aLock; +}; + +//================================================================== +//= OEnumerationByName +//================================================================== +/** provides an <type scope="com.sun.star.container">XEnumeration</type> access based + on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface +*/ +class COMPHELPER_DLLPUBLIC OEnumerationByName : private OEnumerationLock + , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration , + starlang::XEventListener > +{ + staruno::Sequence< OUString > m_aNames; + sal_Int32 m_nPos; + staruno::Reference< starcontainer::XNameAccess > m_xAccess; + sal_Bool m_bListening; + +public: + OEnumerationByName(const staruno::Reference< starcontainer::XNameAccess >& _rxAccess); + OEnumerationByName(const staruno::Reference< starcontainer::XNameAccess >& _rxAccess, + const staruno::Sequence< OUString >& _aNames ); + virtual ~OEnumerationByName(); + + virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); + virtual staruno::Any SAL_CALL nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); + + virtual void SAL_CALL disposing(const starlang::EventObject& aEvent) throw(staruno::RuntimeException); + +private: + COMPHELPER_DLLPRIVATE void impl_startDisposeListening(); + COMPHELPER_DLLPRIVATE void impl_stopDisposeListening(); +}; + +//================================================================== +//= OEnumerationByIndex +//================================================================== +/** provides an <type scope="com.sun.star.container">XEnumeration</type> access based + on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface +*/ +class COMPHELPER_DLLPUBLIC OEnumerationByIndex : private OEnumerationLock + , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration , + starlang::XEventListener > +{ + sal_Int32 m_nPos; + staruno::Reference< starcontainer::XIndexAccess > m_xAccess; + sal_Bool m_bListening; + +public: + OEnumerationByIndex(const staruno::Reference< starcontainer::XIndexAccess >& _rxAccess); + virtual ~OEnumerationByIndex(); + + virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); + virtual staruno::Any SAL_CALL nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); + + virtual void SAL_CALL disposing(const starlang::EventObject& aEvent) throw(staruno::RuntimeException); + +private: + COMPHELPER_DLLPRIVATE void impl_startDisposeListening(); + COMPHELPER_DLLPRIVATE void impl_stopDisposeListening(); +}; + +//================================================================== +//= OAnyEnumeration +//================================================================== +/** provides an <type scope="com.sun.star.container">XEnumeration</type> + for an outside set vector of Any's. + +*/ +class COMPHELPER_DLLPUBLIC OAnyEnumeration : private OEnumerationLock + , public ::cppu::WeakImplHelper1< starcontainer::XEnumeration > +{ + sal_Int32 m_nPos; + staruno::Sequence< staruno::Any > m_lItems; + +public: + OAnyEnumeration(const staruno::Sequence< staruno::Any >& lItems); + virtual ~OAnyEnumeration(); + + virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); + virtual staruno::Any SAL_CALL nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); + +}; + +//......................................................................... +} +//... namespace comphelper ....................................................... + +#endif // _COMPHELPER_ENUMHELPER_HXX_ + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/eventattachermgr.hxx b/include/comphelper/eventattachermgr.hxx new file mode 100644 index 000000000000..a525e7c4ea54 --- /dev/null +++ b/include/comphelper/eventattachermgr.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_EVENTATTACHERMGR_HXX_ +#define _COMPHELPER_EVENTATTACHERMGR_HXX_ + +#include <com/sun/star/uno/Reference.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace com { namespace sun { namespace star { +namespace uno { + class Exception; + class XComponentContext; +} +namespace script { + class XEventAttacherManager; +} +namespace beans { + class XIntrospection; +} +} } } + + +namespace comphelper +{ + +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager > +createEventAttacherManager( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rxContext ) + throw( ::com::sun::star::uno::Exception ); + +} + +#endif // _COMPHELPER_EVENTATTACHERMGR_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/evtlistenerhlp.hxx b/include/comphelper/evtlistenerhlp.hxx new file mode 100644 index 000000000000..c1bb01fa3aa4 --- /dev/null +++ b/include/comphelper/evtlistenerhlp.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef COMPHELPER_EVENTLISTENERHELPER_HXX +#define COMPHELPER_EVENTLISTENERHELPER_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XEventListener.hpp> +#include <osl/diagnose.h> +#include <cppuhelper/weakref.hxx> +#include "comphelper/comphelperdllapi.h" + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //========================================================================== + //= OCommandsListener + // is helper class to avoid a cycle in refcount between the XEventListener + // and the member XEventBroadcaster + //========================================================================== + class COMPHELPER_DLLPUBLIC OEventListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener > + { + ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XEventListener> m_xListener; + public: + OEventListenerHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>& _rxListener); + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); + }; +//........................................................................ +} // namespace comphelper +//........................................................................ +#endif // COMPHELPER_EVENTLISTENERHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/evtmethodhelper.hxx b/include/comphelper/evtmethodhelper.hxx new file mode 100644 index 000000000000..7ecf08a0fc57 --- /dev/null +++ b/include/comphelper/evtmethodhelper.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef COMPHELPER_EVENTMEHODHELPER_HXX +#define COMPHELPER_EVENMETHODHELPER_HXX +#include <comphelper/sequence.hxx> +//........................................................................ +namespace comphelper +{ + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< OUString> getEventMethodsForType(const ::com::sun::star::uno::Type& type); +//........................................................................ + +} // namespace comphelper +//........................................................................ +#endif // COMPHELPER_EVENTMEHODHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/extract.hxx b/include/comphelper/extract.hxx new file mode 100644 index 000000000000..30cbaaefc6c9 --- /dev/null +++ b/include/comphelper/extract.hxx @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_EXTRACT_HXX_ +#define _COMPHELPER_EXTRACT_HXX_ + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/TypeClass.hpp> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/Any.hxx> +#include "cppu/unotype.hxx" + +namespace cppu +{ + +/** + * Sets enum from int32 value. This function does NOT check for valid enum values! + *<BR> + * @param nEnum int32 enum value + * @param rType enum type + * @return enum or emoty any. + */ +inline ::com::sun::star::uno::Any SAL_CALL int2enum( + sal_Int32 nEnum, const ::com::sun::star::uno::Type & rType ) +{ + if (rType.getTypeClass() == ::com::sun::star::uno::TypeClass_ENUM) + { + int nVal = nEnum; + return ::com::sun::star::uno::Any( &nVal, rType ); + } + return ::com::sun::star::uno::Any(); +} + +/** + * Sets int32 from enum or int in any. + *<BR> + * @param rnEnum [out] int32 enum value + * @param rAny enum or int + * @param sal_True if enum or int value was set else sal_False. + */ +inline sal_Bool SAL_CALL enum2int( sal_Int32 & rnEnum, const ::com::sun::star::uno::Any & rAny ) +{ + if (rAny.getValueTypeClass() == ::com::sun::star::uno::TypeClass_ENUM) + { + rnEnum = * reinterpret_cast< const int * >( rAny.getValue() ); + return sal_True; + } + + return rAny >>= rnEnum; +} + +/** + * Sets int32 from enum or int in any with additional typecheck + * <BR> + * @param rAny enum or int + * @param eRet the enum value as int. If there is not enum of the given type or + * a ::com::sun::star::lang::IllegalArgumentException is thrown + */ +template< typename E > +inline void SAL_CALL any2enum( E & eRet, const ::com::sun::star::uno::Any & rAny ) + throw( ::com::sun::star::lang::IllegalArgumentException ) +{ + // check for type save enum + if (! (rAny >>= eRet)) + { + // if not enum, maybe integer? + sal_Int32 nValue = 0; + if (! (rAny >>= nValue)) + throw ::com::sun::star::lang::IllegalArgumentException(); + + eRet = (E)nValue; + } +} + +/** + * Template function to create an uno::Any from an enum + * + * @DEPRECATED : use makeAny< E >() + * + */ +template< typename E > +inline ::com::sun::star::uno::Any SAL_CALL enum2any( E eEnum ) +{ + return ::com::sun::star::uno::Any( &eEnum, ::cppu::UnoType< E >::get() ); +} + +/** + * Extracts interface from an any. If given any does not hold the demanded interface, + * it will be queried for it. + * If no interface is available, the out ref will be cleared. + *<BR> + * @param rxOut [out] demanded interface + * @param rAny interface + * @return sal_True if any reference (including the null ref) was retrieved from any else sal_False. + */ +template< class T > +inline sal_Bool SAL_CALL extractInterface( + ::com::sun::star::uno::Reference< T > & rxOut, + const ::com::sun::star::uno::Any & rAny ) +{ + rxOut.clear(); + return (rAny >>= rxOut); +} + +/** + * extracts a boolean either as a sal_Bool or an integer from + * an any. If there is no sal_Bool or integer inside the any + * a ::com::sun::star::lang::IllegalArgumentException is thrown + * + */ +inline sal_Bool SAL_CALL any2bool( const ::com::sun::star::uno::Any & rAny ) + throw( ::com::sun::star::lang::IllegalArgumentException ) +{ + if (rAny.getValueTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN) + { + return *(sal_Bool *)rAny.getValue(); + } + else + { + sal_Int32 nValue = 0; + if (! (rAny >>= nValue)) + throw ::com::sun::star::lang::IllegalArgumentException(); + return nValue != 0; + } +} + +/** + * Puts a boolean in an any. + * + * @DEPRECATED : use makeAny< sal_Bool >() + * + */ +inline ::com::sun::star::uno::Any SAL_CALL bool2any( sal_Bool bBool ) +{ + return ::com::sun::star::uno::Any( &bBool, ::getCppuBooleanType() ); +} + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/fileformat.h b/include/comphelper/fileformat.h new file mode 100644 index 000000000000..dbd3f32a1f9a --- /dev/null +++ b/include/comphelper/fileformat.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_FILEFORMAT_H_ +#define _COMPHELPER_FILEFORMAT_H_ + +/* file format versions *************************************************/ + +#define SOFFICE_FILEFORMAT_31 3450 +#define SOFFICE_FILEFORMAT_40 3580 +#define SOFFICE_FILEFORMAT_50 5050 +#define SOFFICE_FILEFORMAT_60 6200 +#define SOFFICE_FILEFORMAT_8 6800 +#define SOFFICE_FILEFORMAT_CURRENT SOFFICE_FILEFORMAT_8 + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/flagguard.hxx b/include/comphelper/flagguard.hxx new file mode 100644 index 000000000000..af1f1ea1e4fd --- /dev/null +++ b/include/comphelper/flagguard.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_FLAGGUARD_HXX +#define COMPHELPER_FLAGGUARD_HXX + +#include "comphelper/scopeguard.hxx" + +//...................................................................................................................... +namespace comphelper +{ +//...................................................................................................................... + + //================================================================================================================== + //= FlagRestorationGuard + //================================================================================================================== + class COMPHELPER_DLLPUBLIC FlagRestorationGuard : public ScopeGuard + { + public: + FlagRestorationGuard( bool& i_flagRef, bool i_temporaryValue, exc_handling i_excHandling = IGNORE_EXCEPTIONS ) + :ScopeGuard( ::boost::bind( RestoreFlag, ::boost::ref( i_flagRef ), !!i_flagRef ), i_excHandling ) + { + i_flagRef = i_temporaryValue; + } + + ~FlagRestorationGuard(); + + private: + static void RestoreFlag( bool& i_flagRef, bool i_originalValue ) + { + i_flagRef = i_originalValue; + } + }; + + //================================================================================================================== + //= FlagGuard + //================================================================================================================== + class COMPHELPER_DLLPUBLIC FlagGuard : public ScopeGuard + { + public: + explicit FlagGuard( bool& i_flagRef, exc_handling i_excHandling = IGNORE_EXCEPTIONS ) + :ScopeGuard( ::boost::bind( ResetFlag, ::boost::ref( i_flagRef ) ), i_excHandling ) + { + i_flagRef = true; + } + + ~FlagGuard(); + + private: + static void ResetFlag( bool& i_flagRef ) + { + i_flagRef = false; + } + }; + +//...................................................................................................................... +} // namespace comphelper +//...................................................................................................................... + +#endif // COMPHELPER_FLAGGUARD_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/genericpropertyset.hxx b/include/comphelper/genericpropertyset.hxx new file mode 100644 index 000000000000..e46c30a4cad4 --- /dev/null +++ b/include/comphelper/genericpropertyset.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_GENERICPROPERTYSET_HXX_ +#define _COMPHELPER_GENERICPROPERTYSET_HXX_ + +#include <comphelper/propertysetinfo.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > GenericPropertySet_CreateInstance( PropertySetInfo* pInfo ); +} + +#endif // _COMPHELPER_GENERICPROPERTYSET_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/guarding.hxx b/include/comphelper/guarding.hxx new file mode 100644 index 000000000000..3931c0284e31 --- /dev/null +++ b/include/comphelper/guarding.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_GUARDING_HXX_ +#define _COMPHELPER_GUARDING_HXX_ + +#include <osl/mutex.hxx> + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +// =================================================================================================== +// = class MutexRelease - +// =================================================================================================== + +/** opposite of OGuard :) + (a mutex is released within the constructor and acquired within the desctructor) + use only when you're sure the mutex is acquired ! +*/ +template <class MUTEX> +class ORelease +{ + MUTEX& m_rMutex; + +public: + ORelease(MUTEX& _rMutex) : m_rMutex(_rMutex) { _rMutex.release(); } + ~ORelease() { m_rMutex.acquire(); } +}; + +typedef ORelease< ::osl::Mutex > MutexRelease; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_GUARDING_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/ihwrapnofilter.hxx b/include/comphelper/ihwrapnofilter.hxx new file mode 100644 index 000000000000..eb0b13957874 --- /dev/null +++ b/include/comphelper/ihwrapnofilter.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_INTERACTIONHANDLERWRAPPER_HXX_ +#define _COMPHELPER_INTERACTIONHANDLERWRAPPER_HXX_ + +#include <com/sun/star/task/XInteractionHandler2.hpp> +#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_ +#include <com/sun/star/task/XInteractionHandler.hpp> +#endif +#ifndef _COM_SUN_STAR_TASK_XINTERACITONREQUEST_ +#include <com/sun/star/task/XInteractionRequest.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_DOUBLEINITIALIZATIONEXCEPTION_ +#include <com/sun/star/frame/DoubleInitializationException.hpp> +#endif + +#include <cppuhelper/implbase2.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper { + + class COMPHELPER_DLLPUBLIC OIHWrapNoFilterDialog : public ::cppu::WeakImplHelper2 + < ::com::sun::star::task::XInteractionHandler2 + , ::com::sun::star::lang::XServiceInfo > + { + com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInter; + + public: + OIHWrapNoFilterDialog( com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > xInteraction ); + ~OIHWrapNoFilterDialog(); + + static OUString SAL_CALL impl_staticGetImplementationName(); + static ::com::sun::star::uno::Sequence< OUString > SAL_CALL impl_staticGetSupportedServiceNames(); + + + //____________________________________________________________________________________________________ + // XInteractionHandler + //____________________________________________________________________________________________________ + + virtual void SAL_CALL handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest) + throw( com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XInteractionHandler2 + //____________________________________________________________________________________________________ + + virtual sal_Bool SAL_CALL handleInteractionRequest( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest) + throw( com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XInitialization + //____________________________________________________________________________________________________ + + 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, + ::com::sun::star::frame::DoubleInitializationException ) ; + + //____________________________________________________________________________________________________ + // XServiceInfo + //____________________________________________________________________________________________________ + + virtual OUString SAL_CALL getImplementationName() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() + throw ( ::com::sun::star::uno::RuntimeException ); + + }; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/implbase_var.hxx b/include/comphelper/implbase_var.hxx new file mode 100644 index 000000000000..fee9eb695c08 --- /dev/null +++ b/include/comphelper/implbase_var.hxx @@ -0,0 +1,436 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +/** This header generates the following template classes with a variable number + of interfaces: + + comphelper::ImplHelper<N> <typename Ifc1, ..., typename Ifc<N> > + comphelper::WeakImplHelper<N> <typename Ifc1, ..., typename Ifc<N> > + comphelper::WeakComponentImplHelper<N> <typename Ifc1, ..., + typename Ifc<N> > + comphelper::ImplInheritanceHelper<N> <typename BaseClass, + typename Ifc1, ..., typename Ifc<N> > + + as already present in headers cppuhelper/implbase<1-12>.hxx and + cppuhelper/compbase<1-12>.hxx. + <N> denotes the number of interface types passed as template arguments. + Don't use this header for interface numbers up to 12; + always use the existing cppuhelper/(impl|comp)base<1-12>.hxx headers + for this purpose, which eases debugging. + + Including this header requires a little discipline, because it has no + include guards. Please use the following external include guard rule + where <N> is the number of interface types: + + #ifndef INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_<N> + #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_<N> + #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER <N> + #include "comphelper/implbase_var.hxx" + #endif + + Additionally you can + + #define COMPHELPER_IMPLBASE_MAX_CTOR_ARGS <N> + + to control the maximum number of templated ctor arguments for the + ImplInheritanceHelper<N> classes. + The default is a maximum of 6 arguments. +*/ + +#ifndef COMPHELPER_IMPLBASE_INTERFACE_NUMBER +#error "you have to define COMPHELPER_IMPLBASE_INTERFACE_NUMBER prior to including comphelper/implbase_var.hxx!" +#endif // ! defined(COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + +#if !defined(COMPHELPER_IMPLBASE_TEST_PHASE) && COMPHELPER_IMPLBASE_INTERFACE_NUMBER <= 12 +#error "include proper header file: cppuhelper/implbase<N>.hxx or cppuhelper/compbase<N>.hxx!" +#endif + +#ifndef COMPHELPER_IMPLBASE_MAX_CTOR_ARGS +#define COMPHELPER_IMPLBASE_MAX_CTOR_ARGS 6 // default +#endif + +#include "cppuhelper/implbase_ex.hxx" +#include "rtl/instance.hxx" +#include "cppuhelper/compbase_ex.hxx" + +#include "boost/preprocessor/cat.hpp" +#include "boost/preprocessor/repetition.hpp" +#include "boost/preprocessor/arithmetic/add.hpp" + +namespace comphelper { + +// Suppress warnings about hidden functions in case any of the IfcN has +// functions named dispose, addEventListener, or removeEventListener: +#if defined __SUNPRO_CC +#pragma disable_warn +#endif + +namespace detail { + +struct BOOST_PP_CAT(class_data, COMPHELPER_IMPLBASE_INTERFACE_NUMBER) +{ + sal_Int16 m_nTypes; + sal_Bool m_storedTypeRefs; + sal_Bool m_storedId; + sal_Int8 m_id[16]; + ::cppu::type_entry m_typeEntries[COMPHELPER_IMPLBASE_INTERFACE_NUMBER + 1]; +}; + +/// @internal +template < BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + typename Ifc), typename Impl > +struct BOOST_PP_CAT(ImplClassData, COMPHELPER_IMPLBASE_INTERFACE_NUMBER) +{ + ::cppu::class_data * operator()() { + static BOOST_PP_CAT(class_data, COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + s_cd = { + COMPHELPER_IMPLBASE_INTERFACE_NUMBER + 1, sal_False, sal_False, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { +#define COMPHELPER_IMPLBASE_classdataList(z_, n_, unused_) \ +{ { BOOST_PP_CAT(Ifc, n_)::static_type }, \ + reinterpret_cast<sal_IntPtr>( static_cast< BOOST_PP_CAT(Ifc, n_) * >( \ + reinterpret_cast<Impl *>(16) ) ) - 16 }, + BOOST_PP_REPEAT(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + COMPHELPER_IMPLBASE_classdataList, ~) +#undef COMPHELPER_IMPLBASE_classdataList + { { ::com::sun::star::lang::XTypeProvider::static_type }, + reinterpret_cast<sal_IntPtr>( + static_cast< ::com::sun::star::lang::XTypeProvider * >( + reinterpret_cast<Impl *>(16) ) ) - 16 } + } + }; + return reinterpret_cast< ::cppu::class_data * >(&s_cd); + } +}; + +} // namespace detail + +/** Implementation helper implementing interface + ::com::sun::star::lang::XTypeProvider and method + XInterface::queryInterface(), but no reference counting. + + @derive + Inherit from this class giving your interface(s) to be implemented as + template argument(s). Your sub class defines method implementations for + these interface(s) including acquire()/release() and delegates incoming + queryInterface() calls to this base class. +*/ +template< BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + typename Ifc) > +class SAL_NO_VTABLE BOOST_PP_CAT(ImplHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + : public ::com::sun::star::lang::XTypeProvider, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc) +{ + /// @internal + struct cd : public ::rtl::StaticAggregate< + ::cppu::class_data, + BOOST_PP_CAT(detail::ImplClassData, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + < + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc), + BOOST_PP_CAT(ImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)< + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)> + > > {}; + +protected: + BOOST_PP_CAT(ImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)() {} + virtual ~BOOST_PP_CAT(ImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)() {} + +public: + virtual ::com::sun::star::uno::Any + SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType ) + throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_query( rType, cd::get(), this ); } + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > + SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_getTypes( cd::get() ); } + virtual ::com::sun::star::uno::Sequence<sal_Int8> + SAL_CALL getImplementationId() + throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_getImplementationId( cd::get() ); } +}; + +/** Implementation helper implementing interfaces + ::com::sun::star::lang::XTypeProvider and + ::com::sun::star::uno::XInterface + which supports weak mechanism to be held weakly + (supporting ::com::sun::star::uno::XWeak thru ::cppu::OWeakObject). + + @derive + Inherit from this class giving your interface(s) to be implemented as + template argument(s). Your sub class defines method implementations for + these interface(s). +*/ +template< BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + typename Ifc) > +class SAL_NO_VTABLE BOOST_PP_CAT(WeakImplHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + : public ::cppu::OWeakObject, + public ::com::sun::star::lang::XTypeProvider, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc) +{ + /// @internal + struct cd : public ::rtl::StaticAggregate< + ::cppu::class_data, + BOOST_PP_CAT(detail::ImplClassData, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + < + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc), + BOOST_PP_CAT(WeakImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)< + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)> + > > {}; + +public: + virtual ::com::sun::star::uno::Any + SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType ) + throw (::com::sun::star::uno::RuntimeException) + { + return ::cppu::WeakImplHelper_query( + rType, cd::get(), this, static_cast<OWeakObject *>(this) ); + } + virtual void SAL_CALL acquire() throw () + { OWeakObject::acquire(); } + virtual void SAL_CALL release() throw () + { OWeakObject::release(); } + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > + SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::WeakImplHelper_getTypes( cd::get() ); } + virtual ::com::sun::star::uno::Sequence<sal_Int8> + SAL_CALL getImplementationId() + throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_getImplementationId( cd::get() ); } +}; + +/** Implementation helper implementing interfaces + ::com::sun::star::lang::XTypeProvider and + ::com::sun::star::uno::XInterface inherting from a BaseClass. + + All acquire() and release() calls are delegated to the BaseClass. + Upon queryInterface(), if a demanded interface is not supported by this + class directly, the request is delegated to the BaseClass. + + @attention + The BaseClass has to be complete in a sense, that + ::com::sun::star::uno::XInterface and + ::com::sun::star::lang::XTypeProvider are implemented properly. + The BaseClass must have at least one ctor that can be called with + COMPHELPER_IMPLBASE_MAX_CTOR_ARGS or fewer arguments. + + @derive + Inherit from this class giving your additional interface(s) to be + implemented as template argument(s). Your sub class defines method + implementations for these interface(s). +*/ +template <typename BaseClass, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + typename Ifc) > +class SAL_NO_VTABLE BOOST_PP_CAT(ImplInheritanceHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + : public BaseClass, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc) +{ + /// @internal + struct cd : public ::rtl::StaticAggregate< + ::cppu::class_data, + BOOST_PP_CAT(detail::ImplClassData, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + < + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc), + BOOST_PP_CAT(ImplInheritanceHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER)< + BaseClass, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)> + > > {}; + +protected: +#define COMPHELPER_IMPLBASE_templctor_args(z_, n_, unused_) \ + BOOST_PP_CAT(T, n_) const& BOOST_PP_CAT(arg, n_) +#define COMPHELPER_IMPLBASE_templctor(z_, n_, classname_) \ + template< BOOST_PP_ENUM_PARAMS( BOOST_PP_ADD(n_, 1), typename T) > \ + explicit BOOST_PP_CAT(classname_, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)( \ + BOOST_PP_ENUM(BOOST_PP_ADD(n_, 1), \ + COMPHELPER_IMPLBASE_templctor_args, ~) ) \ + : BaseClass( BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n_, 1), arg) ) {} + + BOOST_PP_CAT(ImplInheritanceHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)() + : BaseClass() {} + BOOST_PP_REPEAT(COMPHELPER_IMPLBASE_MAX_CTOR_ARGS, + COMPHELPER_IMPLBASE_templctor, ImplInheritanceHelper) + +public: + virtual ::com::sun::star::uno::Any + SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType ) + throw (::com::sun::star::uno::RuntimeException) + { + ::com::sun::star::uno::Any const aRet( + ::cppu::ImplHelper_queryNoXInterface( rType, cd::get(), this ) ); + if (aRet.hasValue()) + return aRet; + return BaseClass::queryInterface( rType ); + } + virtual void SAL_CALL acquire() throw () + { BaseClass::acquire(); } + virtual void SAL_CALL release() throw () + { BaseClass::release(); } + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > + SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) + { + return ::cppu::ImplInhHelper_getTypes( + cd::get(), BaseClass::getTypes() ); + } + virtual ::com::sun::star::uno::Sequence<sal_Int8> + SAL_CALL getImplementationId() + throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_getImplementationId( cd::get() ); } +}; + +// not needed anymore: +#undef COMPHELPER_IMPLBASE_templctor_args +#undef COMPHELPER_IMPLBASE_templctor + +/** Implementation helper supporting + ::com::sun::star::lang::XTypeProvider and + ::com::sun::star::lang::XComponent. + + Upon disposing objects of this class, sub-classes receive a disposing() + call. Objects of this class can be held weakly, i.e. by a + ::com::sun::star::uno::WeakReference. + + @attention + The life-cycle of the passed mutex reference has to be longer than objects + of this class. + + @derive + Inherit from this class giving your interface(s) to be implemented as + template argument(s). Your sub class defines method implementations for + these interface(s). +*/ +template < BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + typename Ifc) > +class SAL_NO_VTABLE BOOST_PP_CAT(WeakComponentImplHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + : public ::cppu::WeakComponentImplHelperBase, + public ::com::sun::star::lang::XTypeProvider, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc) +{ + /// @internal + struct cd : public ::rtl::StaticAggregate< + ::cppu::class_data, + BOOST_PP_CAT(detail::ImplClassData, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + < + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc), + BOOST_PP_CAT(WeakComponentImplHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER)< + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)> + > > {}; + +public: + BOOST_PP_CAT(WeakComponentImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)( + ::osl::Mutex & rMutex ) : WeakComponentImplHelperBase(rMutex) {} + + virtual ::com::sun::star::uno::Any + SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType ) + throw (::com::sun::star::uno::RuntimeException) + { + return ::cppu::WeakComponentImplHelper_query( + rType, cd::get(), this, + static_cast< ::cppu::WeakComponentImplHelperBase * >(this) ); + } + virtual void SAL_CALL acquire() throw () + { WeakComponentImplHelperBase::acquire(); } + virtual void SAL_CALL release() throw () + { WeakComponentImplHelperBase::release(); } + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > + SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::WeakComponentImplHelper_getTypes( cd::get() ); } + virtual ::com::sun::star::uno::Sequence<sal_Int8> + SAL_CALL getImplementationId() + throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_getImplementationId( cd::get() ); } + + // implement XComponent directly avoiding ambiguities: + virtual void SAL_CALL dispose() + throw (::com::sun::star::uno::RuntimeException) + { WeakComponentImplHelperBase::dispose(); } + virtual void SAL_CALL addEventListener( + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener> + const & xListener ) throw (::com::sun::star::uno::RuntimeException) + { WeakComponentImplHelperBase::addEventListener( xListener ); } + virtual void SAL_CALL removeEventListener( + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener> + const & xListener ) throw (::com::sun::star::uno::RuntimeException) + { WeakComponentImplHelperBase::removeEventListener( xListener ); } +}; + +template < BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, + typename Ifc) > +class SAL_NO_VTABLE BOOST_PP_CAT(PartialWeakComponentImplHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + : public ::cppu::WeakComponentImplHelperBase, + public ::com::sun::star::lang::XTypeProvider, + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc) +{ + /// @internal + struct cd : public ::rtl::StaticAggregate< + ::cppu::class_data, + BOOST_PP_CAT(detail::ImplClassData, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER) + < + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc), + BOOST_PP_CAT(PartialWeakComponentImplHelper, + COMPHELPER_IMPLBASE_INTERFACE_NUMBER)< + BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)> + > > {}; + +public: + BOOST_PP_CAT(PartialWeakComponentImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)( + ::osl::Mutex & rMutex ) : WeakComponentImplHelperBase(rMutex) {} + + virtual ::com::sun::star::uno::Any + SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType ) + throw (::com::sun::star::uno::RuntimeException) + { + return ::cppu::WeakComponentImplHelper_query( + rType, cd::get(), this, + static_cast< ::cppu::WeakComponentImplHelperBase * >(this) ); + } + virtual void SAL_CALL acquire() throw () + { WeakComponentImplHelperBase::acquire(); } + virtual void SAL_CALL release() throw () + { WeakComponentImplHelperBase::release(); } + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > + SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::WeakComponentImplHelper_getTypes( cd::get() ); } + virtual ::com::sun::star::uno::Sequence<sal_Int8> + SAL_CALL getImplementationId() + throw (::com::sun::star::uno::RuntimeException) + { return ::cppu::ImplHelper_getImplementationId( cd::get() ); } +}; + + +} // namespace comphelper + +// undef for multiple use/inclusion of this header: +#undef COMPHELPER_IMPLBASE_MAX_CTOR_ARGS +#undef COMPHELPER_IMPLBASE_INTERFACE_NUMBER + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/implementationreference.hxx b/include/comphelper/implementationreference.hxx new file mode 100644 index 000000000000..7957d6437ff5 --- /dev/null +++ b/include/comphelper/implementationreference.hxx @@ -0,0 +1,267 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_IMPLEMENTATIONREFERENCE_HXX +#define _COMPHELPER_IMPLEMENTATIONREFERENCE_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +namespace comphelper +{ + + /** Holds a uno::Reference alongside a C++ implementation pointer + + This template is useful to accomplish the following task: the + client needs an implementation pointer to an object providing + UNO interfaces. It is unsafe to simply store a C++ pointer, + because of the automatic UNO lifetime control. It is + inconvenient to always cast the UNO interface to the C++ + implementation, and what's more, it's mostly unclear to the + casual code reader. + + Thus, this template nicely encapsulate the stated intention, + by holding a uno::Reference internally, and providing simple + C++ pointer semantics to the outside. As a differentiator to + ::rtl::Reference, this template features a getRef() method, + giving you friction-less access to the internal UNO interface, + without extra querying. + + By the way, the pointer semantic of this template include + transitive constness. That means, if this template's instance + is const (e.g. because it is a member of a class which is + accessed in a const method), the pointer returned is also + const. + + As this template is geared towards fast, internal pointer + access, validity of the UNO reference is _not_ checked for + every pointer access. The client of this template is + responsible to check that, whereever necessary, via the is() + method. + + @tpl CppType + The C++ type this class should mimick a pointer to (not the + pointer type itself!). + + @tpl UnoType + The UNO interface type of the object (a uno::Reference to this + type is held internally). + + @tpl XIfType + An unambiguous derivative of UnoType. This is defaulted to + the second template parameter (UnoType), which should normally + just work, since one typically has only single inheritance in + UNO.<p> + Alternatively, when using the + ImplementationReference::createFromQuery() method to create an + instance, this type can serve a different need: if the + provided CppType only derives from XInterface (generally + speaking, derives from a UNO interface above UnoType in the + class hierarchy), then the default XIfType constitutes a + possibly invalid downcast to UnoType. Setting XIfType equal to + CppTypes's most derived UNO interface type then solves this + problem (which is not as arcane as it seems to be. Just + imagine you're providing a C++ abstract interface, which must + provide UNO reference semantics. Naturally, you will derive + this C++ interface only from XInterface, to reduce the number + of ambiguous classes. Even more naturally, it is reasonable to + have UnoType be something different from XInterface, governed + by the usage of the C++ interface) + + @sample ImplementationReference< MyCppType, XMyInterface > + + @sample ImplementationReference< MyAbstractCppType, XMyInterface, XInterface > + for an abstract C++ class + + @see ::rtl::Reference + + */ + template < class CppType, + class UnoType, + class XIfType=UnoType > class ImplementationReference + { + public: + + typedef UnoType UnoInterfaceType; + typedef CppType ImplementationType; + typedef XIfType UnambiguousXInterfaceType; + + /** Default-construct an ImplementationReference + + Uno reference will be invalid, implementation pointer will + be NULL. + */ + ImplementationReference() : + mxRef(), + mpImpl( NULL ) + { + } + + /** Create an ImplementationReference from C++ pointer. + + This constructor does not perform an explicit + QueryInterface on the provided implementation object, but + constructs the UNO reference directly from the given + pointer. This is the fastest, and most often the best way + to create an ImplementationReference. If the conversion + between the implementation object and the required UNO + interface is ambiguous, provide the third template + parameter with a type that can be unambiguously upcasted + to the UNO interface (the second template parameter). + + There are cases, however, where performing a + QueryInterface is the better, albeit slower choice. In + these cases, createFromQuery() should be used. + + @param pImpl + Pointer to the C++ implementation type + + @see createFromQuery() + */ + explicit ImplementationReference( ImplementationType* pImpl ) : + mxRef( static_cast<UnambiguousXInterfaceType*>(pImpl) ), + mpImpl( pImpl ) + { + } + + struct CreateFromQuery { }; + /** Create an ImplementationReference from C++ pointer + + @param pImpl + The pointer to the C++ implementation type, which is + queried for the template-parameterized UNO type. + + @param dummy + Dummy parameter, to distinguish this contructor from the + default unary one (which does not perform a + QueryInterface) + */ + ImplementationReference( ImplementationType* pImpl, CreateFromQuery ) : + mxRef( static_cast<UnambiguousXInterfaceType*>(pImpl), + ::com::sun::star::uno::UNO_QUERY ), + mpImpl( pImpl ) + { + } + + /** Factory method to create an ImplementationReference from + C++ pointer. + + This is a static version of the constructor which creates + an instance of an implementation type which is explicitly + queried for the ImplementationReference's + template-parameterized UNO type. + + @sample + mpRef = mpRef.createFromQuery( new ImplementationType ); + */ + static ImplementationReference createFromQuery( ImplementationType* pImpl ) + { + return ImplementationReference( pImpl, CreateFromQuery() ); + } + + /** Query whether the pointer is still valid. + + Hands off also from the implementation pointer if this + returns false! + */ + bool is() const { return mxRef.is(); } + + /** Get a pointer to the implementation object + + Compatibility method to get an auto_ptr-compatible + interface + */ + ImplementationType* get() { return mpImpl; } + const ImplementationType* get() const { return mpImpl; } + + /** Release all references + + Compatibility method to get an auto_ptr-compatible + interface + */ + void reset() { dispose(); } + + /** Release all references + + This method releases the UNO interface reference, and + clears the C++ pointer to NULL. + */ + void dispose() { mxRef = NULL; mpImpl=NULL; } + + ImplementationType* operator->() { return mpImpl; } + const ImplementationType* operator->() const { return mpImpl; } + + ImplementationType& operator*() { return *mpImpl; } + const ImplementationType& operator*() const { return *mpImpl; } + + /// Access to the underlying UNO reference, without extra querying + ::com::sun::star::uno::Reference< UnoInterfaceType > getRef() { return mxRef; } + + /// Access to the underlying UNO reference, without extra querying + const ::com::sun::star::uno::Reference< UnoInterfaceType >& getRef() const { return mxRef; } + + // default destructor, copy constructor and assignment will do + // ~ImplementationReference(); + // ImplementationReference( const ImplementationReference& ); + // ImplementationReference& operator= ( const ImplementationReference& ); + + /** Comparison operator + + Object identity is defined to be identity of the + implementation pointers. This is in general invalid when + comparing pointers to UNO objects (ambiguous class + hierarchies, optimizations in the bridges, etc.), but okay + for raw C++ pointers (which is what's compared herein). + */ + bool operator==( const ImplementationReference& rhs ) const + { + return mpImpl == rhs.mpImpl; + } + + /** less-than operator + + Object order is defined to be the ordering of the + implementation pointers. This is in general invalid when + comparing pointers to UNO objects (ambiguous class + hierarchies, optimizations in the bridges, etc.), but okay + for raw C++ pointers (which is what's used herein). + + This ordering complies with STL's strict weak ordering + concept. + */ + bool operator<( const ImplementationReference& rhs ) const + { + return mpImpl < rhs.mpImpl; + } + + private: + + // the interface, hard reference to prevent object from vanishing + ::com::sun::star::uno::Reference< UnoInterfaceType > mxRef; + + // the c++ object, for our internal stuff + ImplementationType* mpImpl; + + }; + +} + +#endif // _COMPHELPER_IMPLEMENTATIONREFERENCE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/interaction.hxx b/include/comphelper/interaction.hxx new file mode 100644 index 000000000000..bbd925efd3fa --- /dev/null +++ b/include/comphelper/interaction.hxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_INTERACTION_HXX_ +#define _COMPHELPER_INTERACTION_HXX_ + +#include <comphelper/uno3.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/task/XInteractionApprove.hpp> +#include <com/sun/star/task/XInteractionDisapprove.hpp> +#include <com/sun/star/task/XInteractionAbort.hpp> +#include <com/sun/star/task/XInteractionRetry.hpp> +#include <com/sun/star/task/XInteractionPassword.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //========================================================================= + //= OInteractionSelect + //========================================================================= + /** base class for concrete XInteractionContinuation implementations.<p/> + Instances of the classes maintain a flag indicating if the handler was called. + */ + class OInteractionSelect + { + sal_Bool m_bSelected : 1; /// indicates if the select event occurred + + protected: + OInteractionSelect() : m_bSelected(sal_False) { } + + public: + /// determines whether or not this handler was selected + sal_Bool wasSelected() const { return m_bSelected; } + /// resets the state to "not selected", so you may reuse the handler + void reset() { m_bSelected = sal_False; } + + protected: + void implSelected() { m_bSelected = sal_True; } + }; + + //========================================================================= + //= OInteraction + //========================================================================= + /** template for instantiating concret interaction handlers<p/> + the template argument must eb an interface derived from XInteractionContinuation + */ + template <class INTERACTION> + class OInteraction + :public ::cppu::WeakImplHelper1< INTERACTION > + ,public OInteractionSelect + { + public: + OInteraction() { } + + // XInteractionContinuation + virtual void SAL_CALL select( ) throw(::com::sun::star::uno::RuntimeException); + }; + + //......................................................................... + template <class INTERACTION> + void SAL_CALL OInteraction< INTERACTION >::select( ) throw(::com::sun::star::uno::RuntimeException) + { + implSelected(); + } + + //========================================================================= + //= OInteractionApprove + //========================================================================= + typedef OInteraction< ::com::sun::star::task::XInteractionApprove > OInteractionApprove; + + //========================================================================= + //= OInteractionDispprove + //========================================================================= + typedef OInteraction< ::com::sun::star::task::XInteractionDisapprove > OInteractionDisapprove; + + //========================================================================= + //= OInteractionAbort + //========================================================================= + typedef OInteraction< ::com::sun::star::task::XInteractionAbort > OInteractionAbort; + + //========================================================================= + //= OInteractionRetry + //========================================================================= + typedef OInteraction< ::com::sun::star::task::XInteractionRetry > OInteractionRetry; + + //========================================================================= + //= OInteractionPassword + //========================================================================= + class COMPHELPER_DLLPUBLIC OInteractionPassword : public OInteraction< ::com::sun::star::task::XInteractionPassword > + { + public: + OInteractionPassword() + { + } + + OInteractionPassword( const OUString& _rInitialPassword ) + :m_sPassword( _rInitialPassword ) + { + } + + // XInteractionPassword + virtual void SAL_CALL setPassword( const OUString& _Password ) throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getPassword( ) throw (::com::sun::star::uno::RuntimeException); + + private: + OUString m_sPassword; + }; + + //========================================================================= + //= OInteractionRequest + //========================================================================= + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::task::XInteractionRequest + > OInteractionRequest_Base; + /** implements an interaction request (<type scope="com.sun.star.task">XInteractionRequest</type>)<p/> + at run time, you can freely add any interaction continuation objects + */ + class COMPHELPER_DLLPUBLIC OInteractionRequest : public OInteractionRequest_Base + { + ::com::sun::star::uno::Any + m_aRequest; /// the request we represent + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > + m_aContinuations; /// all registered continuations + + public: + OInteractionRequest(const ::com::sun::star::uno::Any& _rRequestDescription); + + /// add a new continuation + void addContinuation(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >& _rxContinuation); + + // XInteractionRequest + virtual ::com::sun::star::uno::Any SAL_CALL getRequest( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations( ) throw(::com::sun::star::uno::RuntimeException); + }; +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_INTERACTION_HXX_ + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/listenernotification.hxx b/include/comphelper/listenernotification.hxx new file mode 100644 index 000000000000..21e2ea74723b --- /dev/null +++ b/include/comphelper/listenernotification.hxx @@ -0,0 +1,298 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_INC_COMPHELPER_LISTENERNOTIFICATION_HXX +#define COMPHELPER_INC_COMPHELPER_LISTENERNOTIFICATION_HXX + +#include <cppuhelper/interfacecontainer.hxx> + +#include <com/sun/star/lang/XEventListener.hpp> +#include "comphelper/comphelperdllapi.h" + +#include <memory> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= OListenerContainer + //==================================================================== + /** abstract base class which manages a listener container, including + THB's listener notification pattern which cares for removing listeners + which throw an DisposedException upon notification + + Using this class is pretty easy: + <ul> + <li>Derive from it, and overwrite implNotify.</li> + <li>Use <member>impl_addListener</member> and <member>impl_removeListener</member> in your + XFoo::addFooListener and XFoo::removeFooListener methods.</li> + <li>call <member>impl_notify</member> whenever the event you want to notify happened</li> + <li>call <member>disposing</member> upon the disposal of your broadcaster.</li> + </ul> + + See <type>OListenerContainerBase</type> for an implementation which even saves + you some more work, by doing the casts for you. + + @see http://www.openoffice.org/servlets/ReadMsg?list=interface-announce&msgId=494345 + @see OListenerContainerBase + */ + class COMPHELPER_DLLPUBLIC OListenerContainer + { + private: + ::cppu::OInterfaceContainerHelper m_aListeners; + + public: + /** sends a XEventObject::disposing notification to all listeners, and clears the + listener container + + You'll usually call this from within your own dispose/disposing method + */ + void disposing( const ::com::sun::star::lang::EventObject& _rEventSource ); + + /** clears the container without calling <member scope="com::sun::star::lang">XEventListener::disposing</member> + at the listeners + */ + void clear(); + + /** determines whether the listener container is currently empty + */ + inline bool + empty() const SAL_THROW(()); + + /** determines the number of elements in the container + */ + inline size_t + size() const SAL_THROW(()); + + /** creates an iterator for looping through all registered listeners + */ + SAL_WNODEPRECATED_DECLARATIONS_PUSH + ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > createIterator() + { + ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pIterator( new ::cppu::OInterfaceIteratorHelper( m_aListeners ) ); + return pIterator; + } + SAL_WNODEPRECATED_DECLARATIONS_POP + + protected: + OListenerContainer( ::osl::Mutex& _rMutex ); + + virtual ~OListenerContainer(); + + void impl_addListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener ); + void impl_removeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener ); + + /** notifies all listeners of the given event, using THB's notification pattern + + internally, this method will call <member>implNotify</member> for every listener + + @return + <TRUE/> if all listeners have been notified, <FALSE/> else. The latter can happen + if <member>implNotify</member> cancelles the notification loop. + + @see implNotify + */ + bool impl_notify( const ::com::sun::star::lang::EventObject& _rEvent ) SAL_THROW(( ::com::sun::star::uno::Exception )); + + protected: + /** call a single listener + + @pure + + @throws ::com::sun::star::uno::Exception + if the listener throws an exception during notification. Please don't catch + any listener exceptions in your implementation of this method, simply let them + pass to the caller. + + @param _rxListener + specifies the listener to call. Is guaranteed to not be <NULL/> + @param _rEvent + the event to broadcast. This is the same as passed to <member>notify</member>, so if + your base class knows the type passed into <member>notify</member>, it can safely assume + that <arg>_rEvent</arg> is also of this type. + + @return + <TRUE/> if the remaining listeners should be called, <FALSE/> if the notification + loop should be cancelled + + @see notify + */ + virtual bool implNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener, + const ::com::sun::star::lang::EventObject& _rEvent + ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ) = 0; + }; + + //==================================================================== + inline bool OListenerContainer::empty() const SAL_THROW(()) + { + return ( m_aListeners.getLength() == 0 ); + } + + inline size_t OListenerContainer::size() const SAL_THROW(()) + { + return m_aListeners.getLength(); + } + + //==================================================================== + //= OSimpleListenerContainer + //==================================================================== + /** helper class for simple notification of the form LISTENER::METHOD( EVENT ) + + This class is not threadsafe! + + @param LISTENER + the listener class to call, e.g. <type scope="com::sun::star::lang">XEventListener</type> + @param EVENT + the event type to notify, e.g. <type scope="com::sun::star::lang">EventObject</type> + */ + template< class LISTENER, class EVENT > + class OSimpleListenerContainer : protected OListenerContainer + { + public: + typedef LISTENER ListenerClass; + typedef EVENT EventClass; + typedef void ( SAL_CALL LISTENER::*NotificationMethod )( const EventClass& ); + + private: + NotificationMethod m_pNotificationMethod; + + public: + OSimpleListenerContainer( ::osl::Mutex& _rMutex ) + :OListenerContainer( _rMutex ) + ,m_pNotificationMethod( NULL ) + { + } + + inline void addListener( const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener ) + { + OListenerContainer::impl_addListener( _rxListener.get() ); + } + + inline void removeListener( const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener ) + { + OListenerContainer::impl_removeListener( _rxListener.get() ); + } + + // publish some otherwise hidden base functionality + using OListenerContainer::disposing; + using OListenerContainer::clear; + using OListenerContainer::empty; + using OListenerContainer::size; + using OListenerContainer::createIterator; + + /// typed notification + inline bool notify( const EventClass& _rEvent, NotificationMethod _pNotify ) SAL_THROW(( ::com::sun::star::uno::Exception )); + + protected: + inline virtual bool implNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener, + const ::com::sun::star::lang::EventObject& _rEvent + ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); + }; + + //-------------------------------------------------------------------- + template< class LISTENER, class EVENT > + inline bool OSimpleListenerContainer< LISTENER, EVENT >::notify( const EventClass& _rEvent, NotificationMethod _pNotify ) SAL_THROW(( ::com::sun::star::uno::Exception )) + { + m_pNotificationMethod = _pNotify; + bool bRet = OListenerContainer::impl_notify( _rEvent ); + m_pNotificationMethod = NULL; + return bRet; + } + + //-------------------------------------------------------------------- + template< class LISTENER, class EVENT > + inline bool OSimpleListenerContainer< LISTENER, EVENT >::implNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener, + const ::com::sun::star::lang::EventObject& _rEvent ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ) + { + const EventClass& rTypedEvent( static_cast< const EventClass& >( _rEvent ) ); + ListenerClass* pTypedListener( static_cast< ListenerClass* >( _rxListener.get() ) ); + (pTypedListener->*m_pNotificationMethod)( rTypedEvent ); + return true; + } + + //==================================================================== + //= OListenerContainerBase + //==================================================================== + /** is a specialization of OListenerContainer which saves you some additional type casts, + by making the required listener and event types template arguments. + */ + template< class LISTENER, class EVENT > + class OListenerContainerBase : public OListenerContainer + { + public: + typedef LISTENER ListenerClass; + typedef EVENT EventClass; + + public: + inline OListenerContainerBase( ::osl::Mutex& _rMutex ) : OListenerContainer( _rMutex ) + { + } + + inline void addTypedListener( const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener ) + { + OListenerContainer::impl_addListener( _rxListener.get() ); + } + + inline void removeTypedListener( const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener ) + { + OListenerContainer::impl_removeListener( _rxListener.get() ); + } + + inline bool notify( const EventClass& _rEvent ) + { + return OListenerContainer::impl_notify( _rEvent ); + } + + using OListenerContainer::impl_notify; + + protected: + inline virtual bool implNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener, + const ::com::sun::star::lang::EventObject& _rEvent + ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); + + virtual bool implTypedNotify( + const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener, + const EventClass& _rEvent + ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ) = 0; + }; + + template< class LISTENER, class EVENT > + inline bool OListenerContainerBase< LISTENER, EVENT >::implNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener, + const ::com::sun::star::lang::EventObject& _rEvent ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ) + { + return implTypedNotify( + ::com::sun::star::uno::Reference< ListenerClass >( static_cast< ListenerClass* >( _rxListener.get() ) ), + static_cast< const EventClass& >( _rEvent ) + ); + } + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_INC_COMPHELPER_LISTENERNOTIFICATION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/logging.hxx b/include/comphelper/logging.hxx new file mode 100644 index 000000000000..b6356384af3d --- /dev/null +++ b/include/comphelper/logging.hxx @@ -0,0 +1,726 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_LOGGING_HXX +#define COMPHELPER_LOGGING_HXX + +#include <comphelper/comphelperdllapi.h> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/logging/XLogHandler.hpp> +#include <com/sun/star/logging/LogLevel.hpp> + +#include <boost/shared_ptr.hpp> +#include <boost/optional.hpp> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= string conversions, employed by the templatized log* members of + //= EventLogger + //==================================================================== + + namespace log { namespace convert + { + inline const OUString& convertLogArgToString( const OUString& _rValue ) + { + return _rValue; + } + + inline OUString convertLogArgToString( const sal_Char* _pAsciiValue ) + { + return OUString::createFromAscii( _pAsciiValue ); + } + + inline OUString convertLogArgToString( double _nValue ) { return OUString::valueOf( _nValue ); } + inline OUString convertLogArgToString( float _nValue ) { return OUString::valueOf( _nValue ); } + inline OUString convertLogArgToString( sal_Int64 _nValue ) { return OUString::valueOf( _nValue ); } + inline OUString convertLogArgToString( sal_Int32 _nValue ) { return OUString::valueOf( _nValue ); } + inline OUString convertLogArgToString( sal_Int16 _nValue ) { return OUString::valueOf( (sal_Int32)_nValue ); } + inline OUString convertLogArgToString( sal_Unicode _nValue ) { return OUString::valueOf( _nValue ); } + inline OUString convertLogArgToString( sal_Bool _nValue ) { return OUString::valueOf( _nValue ); } + + } } // namespace log::convert + + //==================================================================== + //= EventLogger + //==================================================================== + class EventLogger_Impl; + typedef ::boost::optional< OUString > OptionalString; + + /** encapsulates an <type scope="com::sun::star::logging">XLogger</type> + + The class silences several (unlikely) errors which could potentially happen + when working with a logger. Additionally, it provides some convenience methods + for logging events. + + You can use this class as follows +<pre> + EventLogger aLogger( xContext, sLoggerName ); + .... + aLogger.log( LogLevel::SEVERE, sSomeMessage ); + aLogger.logp( LogLevel::CONFIG, "MyClass", "MyMethod", sSomeMessage, SomeParameter1, SomeParameter2, SomeParameter3 ); +</pre> + + The <code>log</code> and <code>logp</code> calls support up to 6 parameters, which can be of + arbitrary type. For every parameter, there must exist a function <code>convertLogArgToString</code> + which takes an argument of the respective type, and returns a string. + + After a parameter has been converted to a string using the above mentioned + <code>convertLogArgToString</code> function, a placeholder $1$ (resp. $2$ resp. $4$ ...) + in the message will be replaced with this string, and the resulting message will be logged. + */ + class COMPHELPER_DLLPUBLIC EventLogger + { + protected: + ::boost::shared_ptr< EventLogger_Impl > m_pImpl; + + public: + /** creates an <code>EventLogger</code> instance working with a css.logging.XLogger + instance given by ASCII name. + + @param _rxContext + the component context to create services + + @param _rLoggerName + the ASCII name of the logger to create. + */ + EventLogger( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const sal_Char* _pAsciiLoggerName + ); + + ~EventLogger(); + + public: + /// determines whether an event with the given level would be logged + bool isLoggable( const sal_Int32 _nLogLevel ) const; + + //---------------------------------------------------------------- + //- XLogger::log equivalents/wrappers + //- string messages + + /// logs a given message, without any arguments, or source class/method names + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage ); + return false; + } + + /** logs a given message, replacing a placeholder in the message with an argument + + The function takes, additionally to the log level and the message, an arbitrary + argument. This argument is converted to a string using an overloaded function + named <code>convertLogArgToString</code>. Then, a placeholder "$1$" + is searched in the message string, and replaced with the argument string. + */ + template< typename ARGTYPE1 > + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage, ARGTYPE1 _argument1 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); + return false; + } + + /// logs a given message, replacing 2 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2 > + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); + return false; + } + + /// logs a given message, replacing 3 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); + return false; + } + + /// logs a given message, replacing 4 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); + return false; + } + + /// logs a given message, replacing 5 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); + return false; + } + + /// logs a given message, replacing 6 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > + bool log( const sal_Int32 _nLogLevel, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ), + OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); + return false; + } + + //---------------------------------------------------------------- + //- XLogger::log equivalents/wrappers + //- ASCII messages + + /// logs a given message, without any arguments, or source class/method names + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ) ); + return false; + } + + /** logs a given message, replacing a placeholder in the message with an argument + + The function takes, additionally to the log level and the message, an arbitrary + argument. This argument is converted to a string using an overloaded function + named <code>convertLogArgToString</code>. Then, a placeholder "$1$" + is searched in the message string, and replaced with the argument string. + */ + template< typename ARGTYPE1 > + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); + return false; + } + + /// logs a given message, replacing 2 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2 > + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); + return false; + } + + /// logs a given message, replacing 3 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); + return false; + } + + /// logs a given message, replacing 4 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); + return false; + } + + /// logs a given message, replacing 5 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); + return false; + } + + /// logs a given message, replacing 6 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > + bool log( const sal_Int32 _nLogLevel, const sal_Char* _pMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, OUString::createFromAscii( _pMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ), + OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); + return false; + } + + //---------------------------------------------------------------- + //- XLogger::logp equivalents/wrappers + //- string messages + + /// logs a given message, without any arguments, or source class/method names + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage ); + return false; + } + + /** logs a given message, replacing a placeholder in the message with an argument + + The function takes, additionally to the logp level and the message, an arbitrary + argument. This argument is converted to a string using an overloaded function + named <code>convertLogArgToString</code>. Then, a placeholder "$1$" + is searched in the message string, and replaced with the argument string. + */ + template< typename ARGTYPE1 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage, ARGTYPE1 _argument1 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); + return false; + } + + /// logs a given message, replacing 2 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); + return false; + } + + /// logs a given message, replacing 3 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); + return false; + } + + /// logs a given message, replacing 4 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); + return false; + } + + /// logs a given message, replacing 5 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); + return false; + } + + /// logs a given message, replacing 6 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const OUString& _rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, _rMessage, + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ), + OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); + return false; + } + + //---------------------------------------------------------------- + //- XLogger::logp equivalents/wrappers + //- ASCII messages + + /// logs a given ASCII message, without any arguments, or source class/method names + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ) ); + return false; + } + + /** logs a given ASCII message, replacing a placeholder in the message with an argument + + The function takes, additionally to the logp level and the message, an arbitrary + argument. This argument is converted to a string using an overloaded function + named <code>convertLogArgToString</code>. Then, a placeholder "$1$" + is searched in the message string, and replaced with the argument string. + */ + template< typename ARGTYPE1 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 2 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 3 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 4 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 5 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 6 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Char* _pAsciiMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, OUString::createFromAscii( _pAsciiMessage ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ), + OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); + return false; + } + + protected: + bool impl_log( + const sal_Int32 _nLogLevel, + const sal_Char* _pSourceClass, + const sal_Char* _pSourceMethod, + const OUString& _rMessage, + const OptionalString& _rArgument1 = OptionalString(), + const OptionalString& _rArgument2 = OptionalString(), + const OptionalString& _rArgument3 = OptionalString(), + const OptionalString& _rArgument4 = OptionalString(), + const OptionalString& _rArgument5 = OptionalString(), + const OptionalString& _rArgument6 = OptionalString() + ) const; + }; + + //==================================================================== + //= ResourceBasedEventLogger + //==================================================================== + struct ResourceBasedEventLogger_Data; + /** extends the EventLogger class with functionality to load log messages from + a resource bundle. + */ + class COMPHELPER_DLLPUBLIC ResourceBasedEventLogger : public EventLogger + { + private: + ::boost::shared_ptr< ResourceBasedEventLogger_Data > m_pData; + + public: + /** creates a resource based event logger + @param _rxContext + the component context for creating new components + @param _pResourceBundleBaseName + the ASCII base name of the resource bundle to use. Will be used + in conjunction with XResourceBundleLoader::loadResource. + @param _pAsciiLoggerName + the ASCII name of the logger to work with. If NULL, the office-wide + default logger will be used. + + */ + ResourceBasedEventLogger( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const sal_Char* _pResourceBundleBaseName, + const sal_Char* _pAsciiLoggerName = NULL + ); + + //---------------------------------------------------------------- + //- XLogger::log equivalents/wrappers + //- resource IDs + + /// logs a given message, without any arguments, or source class/method names + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ) ); + return false; + } + + /** logs a given message, replacing a placeholder in the message with an argument + + The function takes, additionally to the log level and the message, an arbitrary + argument. This argument is converted to a string using an overloaded function + named <code>convertLogArgToString</code>. Then, a placeholder "$1$" + is searched in the message string, and replaced with the argument string. + */ + template< typename ARGTYPE1 > + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); + return false; + } + + /// logs a given message, replacing 2 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2 > + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); + return false; + } + + /// logs a given message, replacing 3 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); + return false; + } + + /// logs a given message, replacing 4 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); + return false; + } + + /// logs a given message, replacing 5 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); + return false; + } + + /// logs a given message, replacing 6 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > + bool log( const sal_Int32 _nLogLevel, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, NULL, NULL, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ), + OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); + return false; + } + + //---------------------------------------------------------------- + //- XLogger::logp equivalents/wrappers + //- resource IDs + + /// logs a given ASCII message, without any arguments, or source class/method names + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ) ); + return false; + } + + /** logs a given ASCII message, replacing a placeholder in the message with an argument + */ + template< typename ARGTYPE1 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 2 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 3 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 4 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 5 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ) ); + return false; + } + + /// logs a given ASCII message, replacing 6 placeholders in the message with respective values + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5, typename ARGTYPE6 > + bool logp( const sal_Int32 _nLogLevel, const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const sal_Int32 _nMessageResID, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5, ARGTYPE6 _argument6 ) const + { + if ( isLoggable( _nLogLevel ) ) + return impl_log( _nLogLevel, _pSourceClass, _pSourceMethod, impl_loadStringMessage_nothrow( _nMessageResID ), + OptionalString( log::convert::convertLogArgToString( _argument1 ) ), + OptionalString( log::convert::convertLogArgToString( _argument2 ) ), + OptionalString( log::convert::convertLogArgToString( _argument3 ) ), + OptionalString( log::convert::convertLogArgToString( _argument4 ) ), + OptionalString( log::convert::convertLogArgToString( _argument5 ) ), + OptionalString( log::convert::convertLogArgToString( _argument6 ) ) ); + return false; + } + + private: + OUString impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID ) const; + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_LOGGING_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/make_shared_from_uno.hxx b/include/comphelper/make_shared_from_uno.hxx new file mode 100644 index 000000000000..2a70094a3f94 --- /dev/null +++ b/include/comphelper/make_shared_from_uno.hxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef INCLUDED_COMPHELPER_MAKE_SHARED_FROM_UNO_HXX +#define INCLUDED_COMPHELPER_MAKE_SHARED_FROM_UNO_HXX + +#include "boost/shared_ptr.hpp" +#include <functional> + +namespace comphelper { + +/// @internal +namespace detail { +/// @internal +template <typename T> struct ReleaseFunc : ::std::unary_function<T *, void> { + void operator()( T * p ) const { p->release(); } +}; +} // namespace detail + +/** Makes a boost::shared_ptr from a ref-counted UNO object pointer. + This makes sense if the object is used via UNO (implementing some X + interface) and also internally using its implementation class, e.g. + + <pre> + boost::shared_ptr<MyUnoImpl> const ptr( + comphelper::make_shared_from_UNO( new MyUnoImpl ) ); + ... + xUno->callingUno( uno::Reference<XSomeInterface>( ptr.get() ) ); + ... + takeSharedPtr( ptr ); + ... + </pre> + + @attention The shared_ptr operates on a separate reference counter, so + weak pointers (boost::weak_ptr) are invalidated when the last + shared_ptr is destroyed, although the UNO object may still be + alive. + + @param p object pointer + @return shared_ptr to object +*/ +template <typename T> +inline ::boost::shared_ptr<T> make_shared_from_UNO( T * p ) +{ + p->acquire(); + return ::boost::shared_ptr<T>( p, detail::ReleaseFunc<T>() ); +} + +} // namespace comphelper + +#endif // ! defined(INCLUDED_COMPHELPER_MAKE_SHARED_FROM_UNO_HXX) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/makesequence.hxx b/include/comphelper/makesequence.hxx new file mode 100644 index 000000000000..bc35657db9a8 --- /dev/null +++ b/include/comphelper/makesequence.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_MAKESEQUENCE_HXX_INCLUDED +#define COMPHELPER_MAKESEQUENCE_HXX_INCLUDED + +#include "com/sun/star/uno/Sequence.hxx" +#include "boost/preprocessor/cat.hpp" +#include "boost/preprocessor/repetition.hpp" +#include "boost/preprocessor/arithmetic/add.hpp" + +namespace comphelper { + +/** Creates a uno::Sequence out of one parameter. +*/ +template <typename T> +inline ::com::sun::star::uno::Sequence<T> makeSequence( T const& element ) +{ + return ::com::sun::star::uno::Sequence<T>( &element, 1 ); +} + +#define COMPHELPER_MAKESEQUENCE_assign(z_, n_, unused_) \ + p[n_] = BOOST_PP_CAT(element, n_); + +/** The following preprocessor repetitions generate functions like + + <pre> + template <typename T> + inline ::com::sun::star::uno::Sequence<T> makeSequence( + T const& element0, T const& element1, ... ); + </pre> + + which make a sequence out of the passed elements. + + The maximum number of elements can be set by defining + COMPHELPER_MAKESEQUENCE_MAX_ARGS; its default is 12. +*/ +#define COMPHELPER_MAKESEQUENCE_make(z_, n_, unused_) \ +template <typename T> \ +inline ::com::sun::star::uno::Sequence<T> makeSequence( \ + BOOST_PP_ENUM_PARAMS(n_, T const& element) ) \ +{ \ + ::com::sun::star::uno::Sequence<T> seq( n_ ); \ + T * p = seq.getArray(); \ + BOOST_PP_REPEAT(n_, COMPHELPER_MAKESEQUENCE_assign, ~) \ + return seq; \ +} + +#ifndef COMPHELPER_MAKESEQUENCE_MAX_ARGS +#define COMPHELPER_MAKESEQUENCE_MAX_ARGS 12 +#endif + +BOOST_PP_REPEAT_FROM_TO(2, BOOST_PP_ADD(COMPHELPER_MAKESEQUENCE_MAX_ARGS, 1), + COMPHELPER_MAKESEQUENCE_make, ~) + +#undef COMPHELPER_MAKESEQUENCE_MAX_ARGS +#undef COMPHELPER_MAKESEQUENCE_make +#undef COMPHELPER_MAKESEQUENCE_assign + +} // namespace comphelper + +#endif // ! defined(COMPHELPER_MAKESEQUENCE_HXX_INCLUDED) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/mediadescriptor.hxx b/include/comphelper/mediadescriptor.hxx new file mode 100644 index 000000000000..7c7174644292 --- /dev/null +++ b/include/comphelper/mediadescriptor.hxx @@ -0,0 +1,310 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_MEDIADESCRIPTOR_HXX_ +#define _COMPHELPER_MEDIADESCRIPTOR_HXX_ + +#include <comphelper/sequenceashashmap.hxx> +#include <rtl/ustring.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace com { namespace sun { namespace star { namespace io { + class XInputStream; +} } } } + +namespace comphelper{ + +/** @short can be used to work with a <type scope="::com::sun::star::document">MediaDescriptor</type> + struct. + + @descr It wraps a ::boost::unordered_map around the Sequence< css::beans::PropertyValue >, which + represent the MediaDescriptor item. + Further this helper defines often used functions (as e.g. open of the required streams, + consistent checks etcpp.) and it defines all useable property names. + + @attention This class isnt threadsafe and must be guarded from outside! + */ +class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap +{ + public: + + //--------------------------------------- + /** @short these methods can be used to get the different property names + as static const OUString values. + + @descr Because definition and declaration of static const class members + does not work as expected under windows (under unix it works as well) + these way must be used :-( + */ + static const OUString& PROP_ABORTED(); + static const OUString& PROP_ASTEMPLATE(); + static const OUString& PROP_COMPONENTDATA(); + static const OUString& PROP_DOCUMENTSERVICE(); + static const OUString& PROP_ENCRYPTIONDATA(); + static const OUString& PROP_FILENAME(); + static const OUString& PROP_FILTERNAME(); + static const OUString& PROP_FILTERPROVIDER(); + static const OUString& PROP_FILTEROPTIONS(); + static const OUString& PROP_FRAME(); + static const OUString& PROP_FRAMENAME(); + static const OUString& PROP_HIDDEN(); + static const OUString& PROP_INPUTSTREAM(); + static const OUString& PROP_INTERACTIONHANDLER(); + static const OUString& PROP_JUMPMARK(); + static const OUString& PROP_MACROEXECUTIONMODE(); + static const OUString& PROP_MEDIATYPE(); + static const OUString& PROP_MINIMIZED(); + static const OUString& PROP_NOAUTOSAVE(); + static const OUString& PROP_OPENNEWVIEW(); + static const OUString& PROP_OUTPUTSTREAM(); + static const OUString& PROP_PASSWORD(); + static const OUString& PROP_POSTDATA(); + static const OUString& PROP_PREVIEW(); + static const OUString& PROP_READONLY(); + static const OUString& PROP_REFERRER(); + static const OUString& PROP_SALVAGEDFILE(); + static const OUString& PROP_STATUSINDICATOR(); + static const OUString& PROP_STREAM(); + static const OUString& PROP_STREAMFOROUTPUT(); + static const OUString& PROP_TEMPLATENAME(); + static const OUString& PROP_TITLE(); + static const OUString& PROP_TYPENAME(); + static const OUString& PROP_UCBCONTENT(); + static const OUString& PROP_UPDATEDOCMODE(); + static const OUString& PROP_URL(); + static const OUString& PROP_VERSION(); + static const OUString& PROP_DOCUMENTTITLE(); + static const OUString& PROP_MODEL(); + static const OUString& PROP_VIEWONLY(); + static const OUString& PROP_DOCUMENTBASEURL(); + + static const OUString& PROP_DEEPDETECTION(); + + //------------------------------------------- + // interface + public: + //--------------------------------------- + /** @short these ctors do nothing - excepting that they forward + the given parameters to the base class ctors. + + @descr The ctros must be overwritten to resolve conflicts with + the default ctors of the compiler :-(. + */ + MediaDescriptor(); + MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource); + + //--------------------------------------- + /** @short it checks if the descriptor already has a valid + InputStream item and creates a new one, if not. + + @descr This method uses the current items of this MediaDescriptor, + to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). + It creates a seekable stream and put it into the descriptor. + + A might existing InteractionHandler will be used automaticly, + to solve problems! + + In case of local file the system file locking is used. + + @return TRUE, if the stream was already part of the descriptor or could + be created as new item. FALSE otherwise. + */ + sal_Bool addInputStream(); + + //--------------------------------------- + /** @short it checks if the descriptor already has a valid + InputStream item and creates a new one, if not. + + @descr This method uses the current items of this MediaDescriptor, + to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). + It creates a seekable stream and put it into the descriptor. + + A might existing InteractionHandler will be used automaticly, + to solve problems! + + In case of local file the system file locking is used based on + configuration settings. + + @return TRUE, if the stream was already part of the descriptor or could + be created as new item. FALSE otherwise. + */ + sal_Bool addInputStreamOwnLock(); + + //--------------------------------------- + /** @short it checks if the descriptor describes a readonly stream. + + @descr The descriptor itself isnt changed doing so. + It's only checked if the stream seems to be based + of a real readonly file. + + @Attention + We dont check the property "ReadOnly" here. Because + this property can be set from outside and overwrites + the readonly state of the stream. + If e.g. the stream could be opened read/write ... + but "ReadOnly" property is set to TRUE, this means: + show a readonly UI on top of this read/write stream. + + @return TRUE, if the stream must be interpreted as readonly ... + FALSE otherwise. + */ + sal_Bool isStreamReadOnly() const; + + //--------------------------------------- + /** Returns a value from the sequence contained in the property + 'ComponentData' of this media descriptor. + + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. + + @return The value with the specified name, if existing in the + sequence of the 'ComponentData' property, otherwise an empty + Any. + */ + ::com::sun::star::uno::Any getComponentDataEntry( + const OUString& rName ) const; + + //--------------------------------------- + /** Inserts a value into the sequence contained in the property + 'ComponentData' of the media descriptor. + + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. The passed value + will be inserted into the sequence, or, if already existing, + will be overwritten. + + @param rName The name of the value to be inserted into the + sequence of the 'ComponentData' property. + + @param rValue The value to be inserted into the sequence of the + 'ComponentData' property. + */ + void setComponentDataEntry( + const OUString& rName, + const ::com::sun::star::uno::Any& rValue ); + + //--------------------------------------- + /** Removes a value from the sequence contained in the property + 'ComponentData' of the media descriptor. + + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. The value with + the passed name will be removed from the sequence, if existing. + + @param rName The name of the value to be removed from the sequence + of the 'ComponentData' property. + */ + void clearComponentDataEntry( + const OUString& rName ); + + //------------------------------------------- + // helper + private: + + //--------------------------------------- + /** @short tries to open a stream by using the given PostData stream. + + @descr The stream is used directly ... + + The MediaDescriptor itself is changed inside this method. + Means: the stream is added internal and not returned by a value. + + @param _rxPostData + the PostData stream. + + @return TRUE if the stream could be added successfully. + Note: If FALSE is returned, the error was already handled inside! + + @throw [css::uno::RuntimeException] + if the MediaDescriptor seems to be invalid! + + @throw [css::lang::IllegalArgumentException] + if the given PostData stream is <NULL/>. + */ + COMPHELPER_DLLPRIVATE sal_Bool impl_openStreamWithPostData( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& _rxPostData + ) throw(::com::sun::star::uno::RuntimeException); + + //--------------------------------------- + /** @short tries to open a stream by using the given URL. + + @descr First it tries to open the content in r/w mode (if its + allowed to do so). Only in case its not allowed or it failed + the stream will be tried to open in readonly mode. + + The MediaDescriptor itself is changed inside this method. + Means: the stream is added internal and not returned by a value. + + @param sURL + the URL for open. + + @param bLockFile + specifies whether the file should be locked + + @return TRUE if the stream could be added successfully. + Note: If FALSE is returned, the error was already handled inside! + + @throw [css::uno::RuntimeException] + if the MediaDescriptor seems to be invalid! + */ + COMPHELPER_DLLPRIVATE sal_Bool impl_openStreamWithURL( + const OUString& sURL, + sal_Bool bLockFile + ) throw(::com::sun::star::uno::RuntimeException); + + //--------------------------------------- + /** @short some URL parts can make trouble for opening streams (e.g. jumpmarks.) + An URL should be "normalized" before its used. + + @param sURL + the original URL (e.g. including a jumpmark) + + @return [string] + the "normalized" URL (e.g. without jumpmark) + */ + COMPHELPER_DLLPRIVATE OUString impl_normalizeURL(const OUString& sURL); + + //--------------------------------------- + /** @short it checks if the descriptor already has a valid + InputStream item and creates a new one, if not. + + @descr This method uses the current items of this MediaDescriptor, + to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). + It creates a seekable stream and put it into the descriptor. + + A might existing InteractionHandler will be used automaticly, + to solve problems! + + @param bLockFile + specifies whether the file should be locked + + @return TRUE, if the stream was already part of the descriptor or could + be created as new item. FALSE otherwise. + */ + COMPHELPER_DLLPRIVATE sal_Bool impl_addInputStream( sal_Bool bLockFile ); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_MEDIADESCRIPTOR_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/mimeconfighelper.hxx b/include/comphelper/mimeconfighelper.hxx new file mode 100644 index 000000000000..6e2b128d5a23 --- /dev/null +++ b/include/comphelper/mimeconfighelper.hxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_ +#define _COMPHELPER_MIMECONFIGHELPER_HXX_ + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XContainerQuery.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/embed/VerbDescriptor.hpp> +#include "comphelper/comphelperdllapi.h" + + +namespace comphelper { + +class COMPHELPER_DLLPUBLIC MimeConfigurationHelper +{ + ::osl::Mutex m_aMutex; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xConfigProvider; + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xObjectConfig; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xVerbsConfig; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xMediaTypeConfig; + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xFilterFactory; + +public: + + MimeConfigurationHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); + + + static OUString GetStringClassIDRepresentation( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID ); + + static ::com::sun::star::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation( const OUString& aClassID ); + + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + GetConfigurationByPath( const OUString& aPath ); + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetObjConfiguration(); + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetVerbsConfiguration(); + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetMediaTypeConfiguration(); + + + OUString GetDocServiceNameFromFilter( const OUString& aFilterName ); + + OUString GetDocServiceNameFromMediaType( const OUString& aMediaType ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjPropsFromConfigEntry( + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xObjectProps ); + + sal_Bool GetVerbByShortcut( const OUString& aVerbShortcut, + ::com::sun::star::embed::VerbDescriptor& aDescriptor ); + + OUString GetExplicitlyRegisteredObjClassID( const OUString& aMediaType ); + + + // retrieving object description from configuration + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByStringClassID( + const OUString& aStringClassID ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByClassID( + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByMediaType( + const OUString& aMediaType ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByFilter( + const OUString& aFilterName ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByDocumentName( + const OUString& aDocumentName ); + + // retrieving object factory from configuration + OUString GetFactoryNameByStringClassID( const OUString& aStringClassID ); + OUString GetFactoryNameByClassID( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID ); + OUString GetFactoryNameByDocumentName( const OUString& aDocName ); + OUString GetFactoryNameByMediaType( const OUString& aMediaType ); + + // typedetection related + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetFilterFactory(); + + OUString UpdateMediaDescriptorWithFilterName( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, + sal_Bool bIgnoreType ); + OUString UpdateMediaDescriptorWithFilterName( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aObject ); +#ifdef WNT + sal_Int32 GetFilterFlags( const OUString& aFilterName ); + + sal_Bool AddFilterNameCheckOwnFile( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr ); +#endif + + OUString GetDefaultFilterFromServiceName( const OUString& aServName, sal_Int32 nVersion ); + + OUString GetExportFilterFromImportFilter( const OUString& aImportFilterName ); + + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SearchForFilter( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery >& xFilterQuery, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aSearchRequest, + sal_Int32 nMustFlags, + sal_Int32 nDontFlags ); + + static sal_Bool ClassIDsEqual( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID1, + const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID2 ); + static ::com::sun::star::uno::Sequence< sal_Int8 > GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, + sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11, + sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 ); +}; + +} + +#endif // _COMPHELPER_MIMECONFIGHELPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/namecontainer.hxx b/include/comphelper/namecontainer.hxx new file mode 100644 index 000000000000..6ac5aff190fb --- /dev/null +++ b/include/comphelper/namecontainer.hxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_NAMECONTAINER_HXX_ +#define _COMPHELPER_NAMECONTAINER_HXX_ + +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > + NameContainer_createInstance( ::com::sun::star::uno::Type aType ); +} + +#endif // _COMPHELPER_NAMECONTAINER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/namedvaluecollection.hxx b/include/comphelper/namedvaluecollection.hxx new file mode 100644 index 000000000000..93b53dd14c6c --- /dev/null +++ b/include/comphelper/namedvaluecollection.hxx @@ -0,0 +1,376 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX +#define COMPHELPER_NAMEDVALUECOLLECTION_HXX + +#include <comphelper/comphelperdllapi.h> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> + +#include <memory> +#include <algorithm> +#include <vector> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + // ==================================================================== + // = NamedValueCollection + // ==================================================================== + struct NamedValueCollection_Impl; + /** a collection of named values, packed in various formats. + */ + class COMPHELPER_DLLPUBLIC NamedValueCollection + { + private: + ::std::auto_ptr< NamedValueCollection_Impl > m_pImpl; + + public: + NamedValueCollection(); + + NamedValueCollection( const NamedValueCollection& _rCopySource ); + + NamedValueCollection& operator=( const NamedValueCollection& i_rCopySource ); + + /** constructs a collection + @param _rElements + the wrapped elements of the collection. The <code>Any</code> might contain a sequence of + property values, a sequence of named values, or directly a property value or named value. + All other cases are worth an assertion in non-product builds. + */ + NamedValueCollection( const ::com::sun::star::uno::Any& _rElements ); + + /** constructs a collection + @param _rArguments + a sequence of Any's containing either PropertyValue's or NamedValue's. + */ + NamedValueCollection( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ); + + /** constructs a collection + @param _rArguments + a sequence of PropertyValues's + */ + NamedValueCollection( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArguments ); + + /** constructs a collection + @param _rArguments + a sequence of NamedValue's + */ + NamedValueCollection( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments ); + + ~NamedValueCollection(); + + inline void assign( const ::com::sun::star::uno::Any& i_rWrappedElements ) + { + impl_assign( i_rWrappedElements ); + } + + inline void assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ) + { + impl_assign( _rArguments ); + } + + inline void assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArguments ) + { + impl_assign( _rArguments ); + } + + inline void assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments ) + { + impl_assign( _rArguments ); + } + + inline void clear() + { + impl_assign( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() ); + } + + /** determines whether or not named values can be extracted from the given value + + @return + <TRUE/> if and only if the given <code>Any</code> contains a <code>NamedValue</code>, a + <code>PropertyValue</code>, or a sequence thereof. + */ + static bool canExtractFrom( ::com::sun::star::uno::Any const & i_value ); + + /// returns the number of elements in the collection + size_t size() const; + + /// determines whether the collection is empty + bool empty() const; + + /** returns the names of all elements in the collection + */ + ::std::vector< OUString > + getNames() const; + + /** merges the content of another collection into |this| + @param _rAdditionalValues + the collection whose values are to be merged + @param _bOverwriteExisting + defines whether or not elements which are already present in |this| + should be overwritten (<TRUE/>) or preserved (<FALSE/>). + @return |*this| + */ + NamedValueCollection& + merge( + const NamedValueCollection& _rAdditionalValues, + bool _bOverwriteExisting + ); + + /** retrieves a value with a given name from the collection, if it is present + + @param _pAsciiValueName + the ASCII name of the value to retrieve + + @param _out_rValue + is the output parameter taking the desired value upon successful return. If + a value with the given name is not present in the collection, or if a wrong-typed + value is present, then this parameter will not be touched. + + @return + <TRUE/> if there is a value with the given name, which could successfully + be extraced. In this case, <arg>_out_rValue</arg> will contain the requested + value.<br/> + <FALSE/>, if there is no value with the given name. + @throws IllegalArgumentException + in case there is a value with the given name, but it cannot legally assigned to + _out_rValue. + */ + template < typename VALUE_TYPE > + bool get_ensureType( const sal_Char* _pAsciiValueName, VALUE_TYPE& _out_rValue ) const + { + return get_ensureType( OUString::createFromAscii( _pAsciiValueName ), &_out_rValue, ::cppu::UnoType< VALUE_TYPE >::get() ); + } + + template < typename VALUE_TYPE > + bool get_ensureType( const OUString& _rValueName, VALUE_TYPE& _out_rValue ) const + { + return get_ensureType( _rValueName, &_out_rValue, ::cppu::UnoType< VALUE_TYPE >::get() ); + } + + /** retrieves a value with a given name, or defaults it to a given value, if its not present + in the colllection + */ + template < typename VALUE_TYPE > + VALUE_TYPE getOrDefault( const sal_Char* _pAsciiValueName, const VALUE_TYPE& _rDefault ) const + { + return getOrDefault( OUString::createFromAscii( _pAsciiValueName ), _rDefault ); + } + + template < typename VALUE_TYPE > + VALUE_TYPE getOrDefault( const OUString& _rValueName, const VALUE_TYPE& _rDefault ) const + { + VALUE_TYPE retVal( _rDefault ); + get_ensureType( _rValueName, retVal ); + return retVal; + } + + /** retrieves a (untyped) value with a given name + + If the collection does not contain a value with the given name, an empty + Any is returned. + */ + const ::com::sun::star::uno::Any& get( const sal_Char* _pAsciiValueName ) const + { + return get( OUString::createFromAscii( _pAsciiValueName ) ); + } + + /** retrieves a (untyped) value with a given name + + If the collection does not contain a value with the given name, an empty + Any is returned. + */ + const ::com::sun::star::uno::Any& get( const OUString& _rValueName ) const + { + return impl_get( _rValueName ); + } + + /// determines whether a value with a given name is present in the collection + inline bool has( const sal_Char* _pAsciiValueName ) const + { + return impl_has( OUString::createFromAscii( _pAsciiValueName ) ); + } + + /// determines whether a value with a given name is present in the collection + inline bool has( const OUString& _rValueName ) const + { + return impl_has( _rValueName ); + } + + /** puts a value into the collection + + @return <TRUE/> if and only if a value was already present previously, in + which case it has been overwritten. + */ + template < typename VALUE_TYPE > + inline bool put( const sal_Char* _pAsciiValueName, const VALUE_TYPE& _rValue ) + { + return impl_put( OUString::createFromAscii( _pAsciiValueName ), ::com::sun::star::uno::makeAny( _rValue ) ); + } + + /** puts a value into the collection + + @return <TRUE/> if and only if a value was already present previously, in + which case it has been overwritten. + */ + template < typename VALUE_TYPE > + inline bool put( const OUString& _rValueName, const VALUE_TYPE& _rValue ) + { + return impl_put( _rValueName, ::com::sun::star::uno::makeAny( _rValue ) ); + } + + inline bool put( const sal_Char* _pAsciiValueName, const ::com::sun::star::uno::Any& _rValue ) + { + return impl_put( OUString::createFromAscii( _pAsciiValueName ), _rValue ); + } + + inline bool put( const OUString& _rValueName, const ::com::sun::star::uno::Any& _rValue ) + { + return impl_put( _rValueName, _rValue ); + } + + /** removes the value with the given name from the collection + + @return <TRUE/> if and only if a value with the given name existed in the collection. + */ + inline bool remove( const sal_Char* _pAsciiValueName ) + { + return impl_remove( OUString::createFromAscii( _pAsciiValueName ) ); + } + + /** removes the value with the given name from the collection + + @return <TRUE/> if and only if a value with the given name existed in the collection. + */ + inline bool remove( const OUString& _rValueName ) + { + return impl_remove( _rValueName ); + } + + /** transforms the collection to a sequence of PropertyValues + + @return + the number of elements in the sequence + */ + sal_Int32 operator >>= ( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _out_rValues ) const; + + /** transforms the collection to a sequence of NamedValues + + @return + the number of elements in the sequence + */ + sal_Int32 operator >>= ( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _out_rValues ) const; + + /** transforms the collection into a sequence of PropertyValues + */ + inline ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > + getPropertyValues() const + { + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aValues; + *this >>= aValues; + return aValues; + } + + /** returns a Sequence< Any >, containing PropertyValues + */ + inline ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > + getWrappedPropertyValues() const + { + return impl_wrap< ::com::sun::star::beans::PropertyValue >(); + } + + /** returns a Sequence< Any >, containing NamedValues + */ + inline ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > + getWrappedNamedValues() const + { + return impl_wrap< ::com::sun::star::beans::NamedValue >(); + } + + /** transforms the collection into a sequence of NamedValues + */ + inline ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > + getNamedValues() const + { + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > aValues; + *this >>= aValues; + return aValues; + } + + private: + void impl_assign( const ::com::sun::star::uno::Any& i_rWrappedElements ); + void impl_assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ); + void impl_assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArguments ); + void impl_assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments ); + + bool get_ensureType( + const OUString& _rValueName, + void* _pValueLocation, + const ::com::sun::star::uno::Type& _rExpectedValueType + ) const; + + const ::com::sun::star::uno::Any& + impl_get( const OUString& _rValueName ) const; + + bool impl_has( const OUString& _rValueName ) const; + + bool impl_put( const OUString& _rValueName, const ::com::sun::star::uno::Any& _rValue ); + + bool impl_remove( const OUString& _rValueName ); + + template< class VALUE_TYPE > + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > impl_wrap() const + { + ::com::sun::star::uno::Sequence< VALUE_TYPE > aValues; + *this >>= aValues; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aWrappedValues( aValues.getLength() ); + ::com::sun::star::uno::Any (* const makeAny)(const VALUE_TYPE&) = ::com::sun::star::uno::makeAny< VALUE_TYPE >; + ::std::transform( + aValues.getConstArray(), + aValues.getConstArray() + aValues.getLength(), + aWrappedValues.getArray(), + makeAny + ); + return aWrappedValues; + } + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_NAMEDVALUECOLLECTION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/newarray.hxx b/include/comphelper/newarray.hxx new file mode 100644 index 000000000000..b64095ae8ff4 --- /dev/null +++ b/include/comphelper/newarray.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_NEW_ARRAY_HXX +#define COMPHELPER_NEW_ARRAY_HXX + +#include <limits> +#include <new> +#include <stddef.h> + +namespace comphelper { + +template<typename T> T * +newArray_null(size_t const n) throw() +{ + if (((::std::numeric_limits<size_t>::max)() / sizeof(T)) <= n) { + return 0; + } + return new (::std::nothrow) T[n]; +} + +template<typename T> T * +newArray_ex(size_t const n) +{ + if (((::std::numeric_limits<size_t>::max)() / sizeof(T)) <= n) { + throw ::std::bad_alloc(); + } + return new T[n]; +} + +} // namespace comphelper + +#endif // COMPHELPER_NEW_ARRAY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/numberedcollection.hxx b/include/comphelper/numberedcollection.hxx new file mode 100644 index 000000000000..6a311767658d --- /dev/null +++ b/include/comphelper/numberedcollection.hxx @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_NUMBEREDCOLLECTION_HXX_ +#define _COMPHELPER_NUMBEREDCOLLECTION_HXX_ + +#include "comphelper/comphelperdllapi.h" + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/frame/XUntitledNumbers.hpp> + +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/weakref.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <vector> +#include <boost/unordered_map.hpp> + + +namespace comphelper{ + +/** @short defines a collection of UNO components, where every component will get it's own unique number. + + @descr Such number will be unique at runtime only ... but it supports fragmentation. + Note: This collection uses weak refrences only to know her components. + So lifetime of thise components must be controlled outside. + + @threadsafe + */ +class COMPHELPER_DLLPUBLIC NumberedCollection : private ::cppu::BaseMutex + , public ::cppu::WeakImplHelper1< css::frame::XUntitledNumbers > +{ + //------------------------------------------- + // types, const + private: + + struct TNumberedItem + { + css::uno::WeakReference< css::uno::XInterface > xItem; + ::sal_Int32 nNumber; + }; + + typedef ::boost::unordered_map< + long , + TNumberedItem , + ::boost::hash< long > , + ::std::equal_to< long > > TNumberedItemHash; + + typedef ::std::vector< long > TDeadItemList; + + //------------------------------------------- + // interface + public: + + //--------------------------------------- + /** @short lightweight constructor. + */ + NumberedCollection(); + + //--------------------------------------- + /** @short free all internaly used resources. + */ + virtual ~NumberedCollection(); + + //--------------------------------------- + /** set an outside component which uses this container and must be set + as source of all broadcasted messages, exceptions. + + It's holded weak only so we do not need any complex dispose sessions. + + Note: Passing NULL as parameter will be allowed. It will reset the internal + member reference only. + + @param xOwner + the new owner of this collection. + */ + void setOwner (const css::uno::Reference< css::uno::XInterface >& xOwner); + + //--------------------------------------- + /** set the localized prefix to be used for untitled components. + + Localization has to be done outside. This container will return + those value then. There are no further checks. Its up to you to define + a suitable string here :-) + + @param sPrefix + the new prefix for untitled components. + */ + void setUntitledPrefix(const OUString& sPrefix); + + //--------------------------------------- + /** @see css.frame.XUntitledNumbers */ + virtual ::sal_Int32 SAL_CALL leaseNumber(const css::uno::Reference< css::uno::XInterface >& xComponent) + throw (css::lang::IllegalArgumentException, + css::uno::RuntimeException ); + + //--------------------------------------- + /** @see css.frame.XUntitledNumbers */ + virtual void SAL_CALL releaseNumber(::sal_Int32 nNumber) + throw (css::lang::IllegalArgumentException, + css::uno::RuntimeException ); + + //--------------------------------------- + /** @see css.frame.XUntitledNumbers */ + virtual void SAL_CALL releaseNumberForComponent(const css::uno::Reference< css::uno::XInterface >& xComponent) + throw (css::lang::IllegalArgumentException, + css::uno::RuntimeException ); + + //--------------------------------------- + /** @see css.frame.XUntitledNumbers */ + virtual OUString SAL_CALL getUntitledPrefix() + throw (css::uno::RuntimeException); + + //------------------------------------------- + // internal + private: + + //--------------------------------------- + /** @short trys to find an unique number not already used within this collection. + + @descr It reuses the smalles number which isnt used by any component + of this collection. (fragmentation!) If collection is full (means there + is no free number) the special value INVALID_NUMBER will be returned. + + @note Those method cant be called within a multithreaded environment .. + Because such number wont be "reserved" for the calli of these method + it can happen that two calls returns the same number (reasoned by the fact that first calli + doesnt used the returned number already. + + So the outside code has to make sure that retrieving and using of those number + will be an atomic operation. + + @return an unique number or special value INVALID_NUMBER if collection is full. + */ + ::sal_Int32 impl_searchFreeNumber (); + + void impl_cleanUpDeadItems ( TNumberedItemHash& lItems , + const TDeadItemList& lDeadItems); + + //------------------------------------------- + // member + private: + + /// localized string to be used for untitled components + OUString m_sUntitledPrefix; + + /// cache of all "leased numbers" and its bound components + TNumberedItemHash m_lComponents; + + /// used as source of broadcasted messages or exceptions (can be null !) + css::uno::WeakReference< css::uno::XInterface > m_xOwner; +}; + +} // namespace comphelper + +#endif // _COMPHELPER_NUMBEREDCOLLECTION_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/numbers.hxx b/include/comphelper/numbers.hxx new file mode 100644 index 000000000000..b64fe341da4f --- /dev/null +++ b/include/comphelper/numbers.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_NUMBERS_HXX_ +#define _COMPHELPER_NUMBERS_HXX_ + +#include <com/sun/star/util/XNumberFormats.hpp> +#include <com/sun/star/util/XNumberFormatter.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starlang = ::com::sun::star::lang; + namespace starutil = ::com::sun::star::util; + + /// returns the ::com::sun::star::util::NumberFormat of the given key under the given formats + COMPHELPER_DLLPUBLIC sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey); + + /// returns the ::com::sun::star::util::NumberFormat of the given key under the given formatter + COMPHELPER_DLLPUBLIC sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormatter>& xFormatter, sal_Int32 nKey); + + /// returns the decimals of the given numeric number formatunder the given formats + COMPHELPER_DLLPUBLIC staruno::Any getNumberFormatDecimals(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey); + + /** returns the standard format for the given type and the given _rLocale + */ + sal_Int32 getStandardFormat( + const staruno::Reference<starutil::XNumberFormatter>& xFormatter, + sal_Int16 nType, + const starlang::Locale& _rLocale); + + /** retrieves a the value of a given property for a given format key, relating to a given formatter + */ + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Any getNumberFormatProperty( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, + sal_Int32 _nKey, + const OUString& _rPropertyName + ); + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_NUMBERS_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/officeresourcebundle.hxx b/include/comphelper/officeresourcebundle.hxx new file mode 100644 index 000000000000..5e6d9e1bccc5 --- /dev/null +++ b/include/comphelper/officeresourcebundle.hxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_OFFICE_RESOURCE_BUNDLE_HXX +#define COMPHELPER_OFFICE_RESOURCE_BUNDLE_HXX + +#include <comphelper/comphelperdllapi.h> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <rtl/ustring.hxx> + +#include <memory> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= OfficeResourceBundle + //==================================================================== + class ResourceBundle_Impl; + /** wraps the <type scope="com::sun::star::resource">OfficeResourceAccess</type> service + */ + class COMPHELPER_DLLPUBLIC OfficeResourceBundle + { + private: + ::std::auto_ptr< ResourceBundle_Impl > m_pImpl; + + public: + /** constructs a resource bundle with the resource bundle given as 8-bit ASCII name + + This is a convenience constructor only, it does nothing different than the constructor + taking an unicode string. + + @param _context + the component context to operate in + @param _bundleBaseName + the base name of the resource file which should be accessed (*without* the SUPD!) + @raises ::com::sun::star::lang::NullPointerException + if the given component context is <NULL/> + */ + OfficeResourceBundle( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _context, + const sal_Char* _bundleBaseAsciiName + ); + + /** destroys the instance + */ + ~OfficeResourceBundle(); + + /** loads the string with the given resource id from the resource bundle + @param _resourceId + the id of the string to load + @return + the requested resource string. If no string with the given id exists in the resource bundle, + an empty string is returned. In a non-product version, an OSL_ENSURE will notify you of this + then. + */ + OUString loadString( sal_Int32 _resourceId ) const; + + /** determines whether the resource bundle has a string with the given id + @param _resourceId + the id of the string whose existence is to be checked + @return + <TRUE/> if and only if a string with the given ID exists in the resource + bundle. + */ + bool hasString( sal_Int32 _resourceId ) const; + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_OFFICE_RESOURCE_BUNDLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/ofopxmlhelper.hxx b/include/comphelper/ofopxmlhelper.hxx new file mode 100644 index 000000000000..e054d0dbc909 --- /dev/null +++ b/include/comphelper/ofopxmlhelper.hxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_OFOPXMLHELPER_HXX +#define _COMPHELPER_OFOPXMLHELPER_HXX + +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/beans/StringPair.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/comphelperdllapi.h> + + +namespace comphelper +{ + +// this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format +class COMPHELPER_DLLPUBLIC OFOPXMLHelper : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler > +{ + sal_uInt16 m_nFormat; // which format to parse + + // Relations info related strings + OUString m_aRelListElement; + OUString m_aRelElement; + OUString m_aIDAttr; + OUString m_aTypeAttr; + OUString m_aTargetModeAttr; + OUString m_aTargetAttr; + + // ContentType related strings + OUString m_aTypesElement; + OUString m_aDefaultElement; + OUString m_aOverrideElement; + OUString m_aExtensionAttr; + OUString m_aPartNameAttr; + OUString m_aContentTypeAttr; + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aResultSeq; + ::com::sun::star::uno::Sequence< OUString > m_aElementsSeq; // stack of elements being parsed + + OFOPXMLHelper( sal_uInt16 nFormat ); // must not be created directly + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetParsingResult(); + + static COMPHELPER_DLLPRIVATE ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL ReadSequence_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const OUString& aStringID, sal_uInt16 nFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) + throw( ::com::sun::star::uno::Exception ); + +public: + ~OFOPXMLHelper(); + + // returns sequence of elements, where each element is described by sequence of tags, + // where each tag is described by StringPair ( First - name, Second - value ) + // the first tag of each element sequence must be "Id" + static + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > + SAL_CALL + ReadRelationsInfoSequence( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, + const OUString aStreamName, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) + throw( ::com::sun::star::uno::Exception ); + + // returns sequence containing two entries of type sequence<StringPair> + // the first sequence describes "Default" elements, where each element is described + // by StringPair object ( First - Extension, Second - ContentType ) + // the second sequence describes "Override" elements, where each element is described + // by StringPair object ( First - PartName, Second - ContentType ) + static + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > + SAL_CALL + ReadContentTypeSequence( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) + throw( ::com::sun::star::uno::Exception ); + + // writes sequence of elements, where each element is described by sequence of tags, + // where each tag is described by StringPair ( First - name, Second - value ) + // the first tag of each element sequence must be "Id" + static + void SAL_CALL WriteRelationsInfoSequence( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aSequence, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) + throw( ::com::sun::star::uno::Exception ); + + // writes two entries of type sequence<StringPair> + // the first sequence describes "Default" elements, where each element is described + // by StringPair object ( First - Extension, Second - ContentType ) + // the second sequence describes "Override" elements, where each element is described + // by StringPair object ( First - PartName, Second - ContentType ) + static + void SAL_CALL WriteContentSequence( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aDefaultsSequence, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aOverridesSequence, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) + throw( ::com::sun::star::uno::Exception ); + + // XDocumentHandler + virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL startElement( const OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL endElement( const OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL characters( const OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); +}; + +} // namespace comphelper + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/optional.hxx b/include/comphelper/optional.hxx new file mode 100644 index 000000000000..031a30328340 --- /dev/null +++ b/include/comphelper/optional.hxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef INCLUDED_COMPHELPER_OPTIONAL_HXX +#define INCLUDED_COMPHELPER_OPTIONAL_HXX + +#include "com/sun/star/beans/Optional.hpp" +#include "boost/optional.hpp" + +namespace comphelper { + +/// Object generators for boost::optional<T>, beans::Optional<T>: + +template <typename T> +inline ::boost::optional<T> make_optional( T const& v ) +{ + return ::boost::optional<T>(v); +} + +template <typename T> +inline ::boost::optional<T> make_optional( + ::com::sun::star::beans::Optional<T> const& o ) +{ + if (o.IsPresent) + return ::boost::optional<T>(o.Value); + else + return ::boost::optional<T>(); +} + +template <typename T> +inline ::com::sun::star::beans::Optional<T> makeOptional( T const& v ) +{ +// CPPU_IS_CPP_MAPPING_OF_NON_VOID_UNO_TYPE(T); + return ::com::sun::star::beans::Optional<T>(true, v); +} + +template <typename T> +inline ::com::sun::star::beans::Optional<T> makeOptional( + ::boost::optional<T> const& o ) +{ +// CPPU_IS_CPP_MAPPING_OF_NON_VOID_UNO_TYPE(T); + if (o) + return ::com::sun::star::beans::Optional<T>(true, *o); + else + return ::com::sun::star::beans::Optional<T>(); +} + +inline ::com::sun::star::beans::Optional<sal_Bool> makeOptional( + ::boost::optional<bool> const& o ) +{ + if (o) + return ::com::sun::star::beans::Optional<sal_Bool>(true, *o); + else + return ::com::sun::star::beans::Optional<sal_Bool>(); +} + +inline ::com::sun::star::beans::Optional<sal_Bool> makeOptional( bool v ) +{ + return ::com::sun::star::beans::Optional<sal_Bool>(true, v); +} + +} // namespace comphelper + +#endif // ! defined(INCLUDED_COMPHELPER_OPTIONAL_HXX) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/oslfile2streamwrap.hxx b/include/comphelper/oslfile2streamwrap.hxx new file mode 100644 index 000000000000..f43297b28b43 --- /dev/null +++ b/include/comphelper/oslfile2streamwrap.hxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ +#define _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ + +#include <osl/mutex.hxx> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <cppuhelper/implbase1.hxx> +#include <osl/file.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +//================================================================== +// FmUnoIOStream, +// Stream to read and write data, based on File +//================================================================== +class COMPHELPER_DLLPUBLIC OSLInputStreamWrapper : public ::cppu::WeakImplHelper1<stario::XInputStream> +{ + ::osl::Mutex m_aMutex; + ::osl::File* m_pFile; + +public: + OSLInputStreamWrapper(::osl::File& _rStream); + virtual ~OSLInputStreamWrapper(); + +// stario::XInputStream + virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException); + virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException); +}; + +//================================================================== +// FmUnoOutStream, +// data sink for the files +//================================================================== +class OSLOutputStreamWrapper : public ::cppu::WeakImplHelper1<stario::XOutputStream> +{ +public: + COMPHELPER_DLLPUBLIC OSLOutputStreamWrapper(::osl::File& _rFile); + +private: + virtual ~OSLOutputStreamWrapper(); + +// stario::XOutputStream + virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + + ::osl::File& rFile; +}; + +} // namespace comphelper + + +#endif // _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/processfactory.hxx b/include/comphelper/processfactory.hxx new file mode 100644 index 000000000000..e6833fc49327 --- /dev/null +++ b/include/comphelper/processfactory.hxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#define _COMPHELPER_PROCESSFACTORY_HXX_ + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace com { namespace sun { namespace star { namespace lang { + class XMultiServiceFactory; +} } } } + +namespace comphelper +{ + +/** + * This function set the process service factory. + * + * @author Juergen Schmidt + */ +COMPHELPER_DLLPUBLIC void setProcessServiceFactory(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMgr); + +/** + * This function gets the process service factory. + * + * If no service factory is set the function throws a RuntimeException. + * + * @author Juergen Schmidt + */ +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getProcessServiceFactory(); + +/** Obtains a component context from a service factory. + + Throws a RuntimeException if no component context can be obtained. + + @param factory may be null + @return may be null + */ +COMPHELPER_DLLPUBLIC +com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > +getComponentContext( + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + const & factory); + +/** + * This function gets the process service factory's default component context. + * + * Throws a RuntimeException if no component context can be obtained. + */ +COMPHELPER_DLLPUBLIC +::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > +getProcessComponentContext(); + +} + + +extern "C" { +/// @internal ATTENTION returns ACQUIRED pointer! release it explicitly! +COMPHELPER_DLLPUBLIC +::com::sun::star::uno::XComponentContext * +comphelper_getProcessComponentContext(); +} // extern "C" + +#endif // _COMPHELPER_PROCESSFACTORY_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propagg.hxx b/include/comphelper/propagg.hxx new file mode 100644 index 000000000000..3a6ca83e36c1 --- /dev/null +++ b/include/comphelper/propagg.hxx @@ -0,0 +1,325 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTY_AGGREGATION_HXX_ +#define _COMPHELPER_PROPERTY_AGGREGATION_HXX_ + +#include <com/sun/star/uno/XAggregation.hpp> +#include <comphelper/propstate.hxx> +#include "comphelper/comphelperdllapi.h" + +#include <map> + +//========================================================================= +//= property helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//================================================================== +//= OPropertyAccessor +//= internal helper class for OPropertyArrayAggregationHelper +//================================================================== +namespace internal +{ + struct OPropertyAccessor + { + sal_Int32 nOriginalHandle; + sal_Int32 nPos; + bool bAggregate; + + OPropertyAccessor(sal_Int32 _nOriginalHandle, sal_Int32 _nPos, bool _bAggregate) + :nOriginalHandle(_nOriginalHandle) ,nPos(_nPos) ,bAggregate(_bAggregate) { } + OPropertyAccessor() + :nOriginalHandle(-1) ,nPos(-1) ,bAggregate(false) { } + + bool operator==(const OPropertyAccessor& rOb) const { return nPos == rOb.nPos; } + bool operator <(const OPropertyAccessor& rOb) const { return nPos < rOb.nPos; } + }; + + typedef std::map< sal_Int32, OPropertyAccessor, ::std::less< sal_Int32 > > PropertyAccessorMap; + typedef PropertyAccessorMap::iterator PropertyAccessorMapIterator; + typedef PropertyAccessorMap::const_iterator ConstPropertyAccessorMapIterator; +} + +//================================================================== +/** + * used as callback for a OPropertyArrayAggregationHelper + */ +class IPropertyInfoService +{ +public: + /** get the prefered handle for the given property + @param _rName the property name + @return the handle the property should be refered by, or -1 if there are no + preferences for the given property + */ + virtual sal_Int32 getPreferedPropertyId(const OUString& _rName) = 0; + +protected: + ~IPropertyInfoService() {} +}; + +/** + * used for implementing an cppu::IPropertyArrayHelper for classes + * aggregating property sets + */ + +#define DEFAULT_AGGREGATE_PROPERTY_ID 10000 +//------------------------------------------------------------------ +class COMPHELPER_DLLPUBLIC OPropertyArrayAggregationHelper: public ::cppu::IPropertyArrayHelper +{ + friend class OPropertySetAggregationHelper; +protected: + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> m_aProperties; + internal::PropertyAccessorMap m_aPropertyAccessors; + +public: + /** construct the object. + @param _rProperties the properties of the object doing the aggregation. These properties + are used without any checks, so the caller has to ensure that the names and + handles are valid. + @param _rAggProperties the properties of the aggregate, usually got via an call to getProperties on the + XPropertySetInfo of the aggregate. + The names of the properties are used without any checks, so the caller has to ensure + that there are no doubles. + The handles are stored for later quick access, but the outside-handles the + aggregate properties get depend from the following two parameters. + @param _pInfoService + If not NULL, the object pointed to is used to calc handles which should be used + for refering the aggregate's properties from outside. + If one of the properties returned from the info service conflict with other handles + alread present (e.g. through _rProperties), the property is handled as if -1 was returned. + If NULL (or, for a special property, a call to getPreferedPropertyId returns -1), + the aggregate property(ies) get a new handle which they can be refered by from outside. + @param _nFirstAggregateId + if the object is about to create new handles for the aggregate properties, it uses + id's ascending from this given id. + No checks are made if the handle range determined by _nFirstAggregateId conflicts with other + handles within _rProperties. + */ + OPropertyArrayAggregationHelper(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property>& _rProperties, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property>& _rAggProperties, + IPropertyInfoService* _pInfoService = NULL, + sal_Int32 _nFirstAggregateId = DEFAULT_AGGREGATE_PROPERTY_ID); + + + /// inherited from IPropertyArrayHelper + virtual sal_Bool SAL_CALL fillPropertyMembersByHandle( OUString* _pPropName, sal_Int16* _pAttributes, + sal_Int32 _nHandle) ; + + /// inherited from IPropertyArrayHelper + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> SAL_CALL getProperties(); + /// inherited from IPropertyArrayHelper + virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName(const OUString& _rPropertyName) + throw(::com::sun::star::beans::UnknownPropertyException); + + /// inherited from IPropertyArrayHelper + virtual sal_Bool SAL_CALL hasPropertyByName(const OUString& _rPropertyName) ; + /// inherited from IPropertyArrayHelper + virtual sal_Int32 SAL_CALL getHandleByName(const OUString & _rPropertyName); + /// inherited from IPropertyArrayHelper + virtual sal_Int32 SAL_CALL fillHandles( /*out*/sal_Int32* _pHandles, const ::com::sun::star::uno::Sequence< OUString >& _rPropNames ); + + /** returns information about a property of the aggregate. + @param _pPropName points to a string to receive the property name. No name is returned if this is NULL. + @param _pOriginalHandle points to a sal_Int32 to receive the original property hande. No original handle is returned + if this is NULL. + @param _nHandle the handle of the property as got by, for instance, fillHandles + + @return sal_True, if _nHandle marks an aggregate property, otherwise sal_False + */ + virtual bool SAL_CALL fillAggregatePropertyInfoByHandle(OUString* _pPropName, sal_Int32* _pOriginalHandle, + sal_Int32 _nHandle) const; + + /** returns information about a property given by handle + */ + sal_Bool getPropertyByHandle( sal_Int32 _nHandle, ::com::sun::star::beans::Property& _rProperty ) const; + + + enum PropertyOrigin + { + AGGREGATE_PROPERTY, + DELEGATOR_PROPERTY, + UNKNOWN_PROPERTY + }; + /** prefer this one over the XPropertySetInfo of the aggregate! + + <p>The reason is that OPropertyArrayAggregationHelper is the only instance which really knows + which properties of the aggregate are to be exposed. <br/> + + For instance, some derivee of OPropertySetAggregationHelper may decide to create an + OPropertyArrayAggregationHelper which contains only a subset of the aggregate properties. This way, + some of the aggregate properties may be hidded to the public.<br/> + + When using the XPropertySetInfo of the aggregate set to determine the existence of a property, then this + would return false positives.</p> + */ + PropertyOrigin classifyProperty( const OUString& _rName ); + +protected: + const ::com::sun::star::beans::Property* findPropertyByName(const OUString& _rName) const; +}; + +//================================================================== +namespace internal +{ + class PropertyForwarder; +} + +/** + * helper class for implementing the property-set-related interfaces + * for an object doin' aggregation + * supports at least XPropertySet and XMultiPropertySet + * + */ +class COMPHELPER_DLLPUBLIC OPropertySetAggregationHelper :public OPropertyStateHelper + ,public ::com::sun::star::beans::XPropertiesChangeListener + ,public ::com::sun::star::beans::XVetoableChangeListener +{ + friend class internal::PropertyForwarder; + +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState> m_xAggregateState; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xAggregateSet; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet> m_xAggregateMultiSet; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet> m_xAggregateFastSet; + + internal::PropertyForwarder* m_pForwarder; + sal_Bool m_bListening : 1; + +public: + OPropertySetAggregationHelper( ::cppu::OBroadcastHelper& rBHelper ); + + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& aType) throw(::com::sun::star::uno::RuntimeException); + +// XEventListener + virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException); + +// XFastPropertySet + virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue) 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); + virtual ::com::sun::star::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + +// XPropertySet + virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + +// XPropertiesChangeListener + virtual void SAL_CALL propertiesChange(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyChangeEvent >& evt) throw(::com::sun::star::uno::RuntimeException); + +// XVetoableChangeListener + virtual void SAL_CALL vetoableChange(const ::com::sun::star::beans::PropertyChangeEvent& aEvent) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException); + +// XMultiPropertySet + virtual void SAL_CALL setPropertyValues(const ::com::sun::star::uno::Sequence< OUString >& PropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener(const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener) throw(::com::sun::star::uno::RuntimeException); + +// XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault(const OUString& aPropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + +// OPropertySetHelper + /** still waiting to be overwritten ... + you <B>must<B/> use an OPropertyArrayAggregationHelper here, as the implementation strongly relies on this. + */ + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() = 0; + + /** only implemented for "forwarded" properties, every other property must be handled + in the derivee, and will assert if passed herein + */ + 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); + + /** only implemented for "forwarded" properties, every other property must be handled + in the derivee, and will assert if passed herein + */ + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) throw ( ::com::sun::star::uno::Exception ); + +protected: + ~OPropertySetAggregationHelper(); + + virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const; + virtual void SAL_CALL disposing(); + + sal_Int32 getOriginalHandle( sal_Int32 _nHandle ) const; + OUString getPropertyName( sal_Int32 _nHandle ) const; + + /** declares the property with the given (public) handle as one to be forwarded to the aggregate + + Sometimes, you might want to <em>overwrite</em> properties at the aggregate. That is, + though the aggregate implements this property, and still is to hold the property value, + you want to do additional handling upon setting the property, but then forward the value + to the aggregate. + + Use this method to declare such properties. + + When a "forwarded property" is set from outside, the class first calls + <member>forwardingPropertyValue</member> for any preprocessing, then forwards the property + value to the aggregate, and then calls <member>forwardedPropertyValue</member>. + + When you declare a property as "forwarded", the class takes care for some multi-threading + issues, for instance, it won't fire any property change notifications which result from + forwarding a property value, unless it's safe to do so (i.e. unless our mutex is + released). + + @see forwardingPropertyValue + @see forwardedPropertyValue + */ + void declareForwardedProperty( sal_Int32 _nHandle ); + + /** checks whether we're actually forwarding a property value to our aggregate + + @see declareForwardedProperty + @see forwardingPropertyValue + @see forwardedPropertyValue + */ + bool isCurrentlyForwardingProperty( sal_Int32 _nHandle ) const; + + /** called immediately before a property value which is overwritten in this instance + is forwarded to the aggregate + + @see declareForwardedProperty + @see forwardedPropertyValue + */ + virtual void SAL_CALL forwardingPropertyValue( sal_Int32 _nHandle ); + + /** called immediately after a property value which is overwritten in this instance + has been forwarded to the aggregate + + @see declareForwardedProperty + @see forwardingPropertyValue + */ + virtual void SAL_CALL forwardedPropertyValue( sal_Int32 _nHandle, bool _bSuccess ); + + /// must be called before aggregation, if aggregation is used + void setAggregation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >&) throw( ::com::sun::star::lang::IllegalArgumentException ); + void startListening(); +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_AGGREGATION_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/proparrhlp.hxx b/include/comphelper/proparrhlp.hxx new file mode 100644 index 000000000000..840213e88427 --- /dev/null +++ b/include/comphelper/proparrhlp.hxx @@ -0,0 +1,175 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_ +#define _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_ + +#include <comphelper/stl_types.hxx> +#include <comphelper/propagg.hxx> +#include <cppuhelper/propshlp.hxx> +#include <osl/mutex.hxx> +#include <osl/diagnose.h> +#include <rtl/instance.hxx> + +namespace cppu { + class IPropertyArrayHelper; +} + +//... namespace comphelper ................................................ +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starbeans = ::com::sun::star::beans; + + +//================================================================== + +template <typename TYPE> struct OPropertyArrayUsageHelperMutex + : public rtl::Static< ::osl::Mutex, OPropertyArrayUsageHelperMutex<TYPE> > {}; + + +template <class TYPE> +class OPropertyArrayUsageHelper +{ +protected: + static sal_Int32 s_nRefCount; + static ::cppu::IPropertyArrayHelper* s_pProps; + +public: + OPropertyArrayUsageHelper(); + virtual ~OPropertyArrayUsageHelper() + { // ARGHHHHHHH ..... would like to implement this after the class + // definition (as we do with all other methods) but SUNPRO 5 compiler + // (linker) doesn't like this + ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get()); + OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); + if (!--s_nRefCount) + { + delete s_pProps; + s_pProps = NULL; + } + } + + /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the + class, which is created if neccessary. + */ + ::cppu::IPropertyArrayHelper* getArrayHelper(); + +protected: + /** used to implement the creation of the array helper which is shared amongst all instances of the class. + This method needs to be implemented in derived classes. + <BR> + The method gets called with Mutex acquired. + <BR> + as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper + assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps. + @return an pointer to the newly created array helper. Must not be NULL. + */ + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0; +}; + +//================================================================== +/** a OPropertyArrayUsageHelper which will create an OPropertyArrayAggregationHelper +*/ +template <class TYPE> +class OAggregationArrayUsageHelper: public OPropertyArrayUsageHelper<TYPE> +{ +protected: + /** overwrite this in your derived class. initialize the two sequences with your and your aggregate's + properties. + <BR> + The method gets called with Mutex acquired. + @param _rProps out parameter to be filled with the property descriptions of your own class + @param _rAggregateProps out parameter to be filled with the properties of your aggregate. + */ + virtual void fillProperties( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps + ) const = 0; + + /** creates an OPropertyArrayAggregationHelper filled with properties for which's initialization + fillProperties is called. getInfoService and getFirstAggregateId may be overwritten to determine + the additional parameters of the OPropertyArrayAggregationHelper. + */ + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + + /** the return value is used for the construction of the OPropertyArrayAggregationHelper. + Beware of the lifetime of the returned object, as it has to exist 'til the last instance + of this class dies. + */ + virtual IPropertyInfoService* getInfoService() const { return NULL; } + + /** the return value is used for the construction of the OPropertyArrayAggregationHelper. + */ + virtual sal_Int32 getFirstAggregateId() const { return DEFAULT_AGGREGATE_PROPERTY_ID; } +}; + +//------------------------------------------------------------------ +template<class TYPE> +sal_Int32 OPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0; + +template<class TYPE> +::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper< TYPE >::s_pProps = NULL; + +//------------------------------------------------------------------ +template <class TYPE> +OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper() +{ + ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get()); + ++s_nRefCount; +} + +//------------------------------------------------------------------ +template <class TYPE> +::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper() +{ + OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); + if (!s_pProps) + { + ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get()); + if (!s_pProps) + { + s_pProps = createArrayHelper(); + OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); + } + } + return s_pProps; +} + +//------------------------------------------------------------------ +template <class TYPE> inline +::cppu::IPropertyArrayHelper* OAggregationArrayUsageHelper<TYPE>::createArrayHelper() const +{ + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aAggregateProps; + fillProperties(aProps, aAggregateProps); + OSL_ENSURE(aProps.getLength(), "OAggregationArrayUsageHelper::createArrayHelper : fillProperties returned nonsense !"); + return new OPropertyArrayAggregationHelper(aProps, aAggregateProps, getInfoService(), getFirstAggregateId()); +} + +//......................................................................... +} +//... namespace comphelper ................................................ + +#endif // _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_ + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/property.hxx b/include/comphelper/property.hxx new file mode 100644 index 000000000000..95fe122d51a6 --- /dev/null +++ b/include/comphelper/property.hxx @@ -0,0 +1,205 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTY_HXX_ +#define _COMPHELPER_PROPERTY_HXX_ + +#include <cppuhelper/proptypehlp.hxx> +#include <comphelper/extract.hxx> +#include <com/sun/star/beans/Property.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <functional> +#include "comphelper/comphelperdllapi.h" +#include "cppu/unotype.hxx" + +//========================================================================= +//= property helper classes +//========================================================================= + +//... namespace comphelper ....................................................... +namespace comphelper +{ +//......................................................................... + + namespace starbeans = ::com::sun::star::beans; + namespace staruno = ::com::sun::star::uno; + +/** compare two properties by name +*/ + //-------------------------------------------------------------------------- + // comparing two property instances + struct PropertyCompareByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool > + { + bool operator() (const ::com::sun::star::beans::Property& x, const ::com::sun::star::beans::Property& y) const + { + return x.Name.compareTo(y.Name) < 0;// ? true : false; + } + }; + + //-------------------------------------------------------------------------- + /** compare two properties by name + */ + struct PropertyStringEqualFunctor : ::std::binary_function< ::com::sun::star::beans::Property, OUString, bool > + { + // ................................................................ + inline bool operator()( const ::com::sun::star::beans::Property& lhs, const OUString& rhs ) const + { + return lhs.Name == rhs ; + } + // ................................................................ + inline bool operator()( const OUString& lhs, const ::com::sun::star::beans::Property& rhs ) const + { + return lhs == rhs.Name ; + } + }; + //-------------------------------------------------------------------------- + // comparing two property instances + struct PropertyEqualByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool > + { + bool operator() (const ::com::sun::star::beans::Property& x, const ::com::sun::star::beans::Property& y) const + { + return x.Name == y.Name ; + } + }; + +//------------------------------------------------------------------ +/// remove the property with the given name from the given sequence +COMPHELPER_DLLPUBLIC void RemoveProperty(staruno::Sequence<starbeans::Property>& seqProps, const OUString& _rPropName); + +//------------------------------------------------------------------ +/** within the given property sequence, modify attributes of a special property + @param _rProps the sequence of properties to search in + @param _sPropName the name of the property which's attributes should be modified + @param _nAddAttrib the attributes which should be added + @param _nRemoveAttrib the attributes which should be removed +*/ +COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(staruno::Sequence<starbeans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib); + +//------------------------------------------------------------------ +/** check if the given set has the given property. +*/ +COMPHELPER_DLLPUBLIC sal_Bool hasProperty(const OUString& _rName, const staruno::Reference<starbeans::XPropertySet>& _rxSet); + +//------------------------------------------------------------------ +/** copy properties between property sets, in compliance with the property + attributes of the target object +*/ +COMPHELPER_DLLPUBLIC void copyProperties(const staruno::Reference<starbeans::XPropertySet>& _rxSource, + const staruno::Reference<starbeans::XPropertySet>& _rxDest); + +//================================================================== +//= property conversion helpers +//================================================================== + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue + @param _rConvertedValue the conversion result (if successful) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) +*/ +template <typename T> +sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, const T& _rCurrentValue) +{ + sal_Bool bModified(sal_False); + T aNewValue = T(); + ::cppu::convertPropertyValue(aNewValue, _rValueToSet); + if (aNewValue != _rCurrentValue) + { + _rConvertedValue <<= aNewValue; + _rOldValue <<= _rCurrentValue; + bModified = sal_True; + } + return bModified; +} + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for enum values + @param _rConvertedValue the conversion result (if successful) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) +*/ +template <class ENUMTYPE> +sal_Bool tryPropertyValueEnum(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, const ENUMTYPE& _rCurrentValue) +{ + if (cppu::getTypeFavourUnsigned(&_rCurrentValue).getTypeClass() + != staruno::TypeClass_ENUM) + return tryPropertyValue(_rConvertedValue, _rOldValue, _rValueToSet, _rCurrentValue); + + sal_Bool bModified(sal_False); + ENUMTYPE aNewValue; + ::cppu::any2enum(aNewValue, _rValueToSet); + // will throw an exception if not convertible + + if (aNewValue != _rCurrentValue) + { + _rConvertedValue <<= aNewValue; + _rOldValue <<= _rCurrentValue; + bModified = sal_True; + } + return bModified; +} + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for boolean properties + @param _rConvertedValue the conversion result (if successful) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to a boolean type +*/ +inline sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, sal_Bool _bCurrentValue) +{ + sal_Bool bModified(sal_False); + sal_Bool bNewValue(sal_False); + ::cppu::convertPropertyValue(bNewValue, _rValueToSet); + if (bNewValue != _bCurrentValue) + { + _rConvertedValue.setValue(&bNewValue, ::getBooleanCppuType()); + _rOldValue.setValue(&_bCurrentValue, ::getBooleanCppuType()); + bModified = sal_True; + } + return bModified; +} + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue + @param _rConvertedValue the conversion result (if successful) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @param _rExpectedType the type which the property should have (if not void) + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) +*/ +COMPHELPER_DLLPUBLIC sal_Bool tryPropertyValue(staruno::Any& _rConvertedValue, staruno::Any& _rOldValue, const staruno::Any& _rValueToSet, const staruno::Any& _rCurrentValue, const staruno::Type& _rExpectedType); + +//......................................................................... +} +//... namespace comphelper ....................................................... + +#endif // _COMPHELPER_PROPERTY_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertybag.hxx b/include/comphelper/propertybag.hxx new file mode 100644 index 000000000000..92c0026ba845 --- /dev/null +++ b/include/comphelper/propertybag.hxx @@ -0,0 +1,227 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_PROPERTYBAG_HXX +#define COMPHELPER_PROPERTYBAG_HXX + +#include "comphelper/comphelperdllapi.h" +#include <comphelper/propertycontainerhelper.hxx> + +#include <memory> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + struct PropertyBag_Impl; + //==================================================================== + //= PropertyBag + //==================================================================== + /** provides a bag of properties associated with their values + + This class can, for instance, be used for components which need to implement + the com.sun.star.beans.PropertyBag service. + */ + class COMPHELPER_DLLPUBLIC PropertyBag : protected OPropertyContainerHelper + { + private: + ::std::auto_ptr< PropertyBag_Impl > m_pImpl; + + public: + PropertyBag(); + virtual ~PropertyBag(); + + /** allow adding property with empty string as name + (by default, such names are rejected with IllegalActionException). + @param i_isAllowed + iff true, empty property name will be allowed + */ + void setAllowEmptyPropertyName(bool i_isAllowed = true); + + /** adds a property to the bag + + The type of the property is determined from its initial value (<code>_rInitialValue</code>). + + @param _rName + the name of the new property. Must not be empty unless + explicitly allowed with setAllowEmptyPropertyName. + @param _nHandle + the handle of the new property + @param _nAttributes + the attributes of the property + @param _rInitialValue + the initial value of the property. Must not be <NULL/>, to allow + determining the property type. + + @throws ::com::sun::star::beans::IllegalTypeException + if the initial value is <NULL/> + @throws ::com::sun::star::beans::PropertyExistException + if the name or the handle are already used + @throws ::com::sun::star::beans::IllegalArgumentException + if the name is empty + */ + void addProperty( + const OUString& _rName, + sal_Int32 _nHandle, + sal_Int32 _nAttributes, + const ::com::sun::star::uno::Any& _rInitialValue + ); + + /** adds a property to the bag + + The initial value of the property is <NULL/>. + + @param _rName + the name of the new property. Must not be empty unless + explicitly allowed with setAllowEmptyPropertyName. + @param _rType + the type of the new property + @param _nHandle + the handle of the new property + @param _nAttributes + the attributes of the property + + @throws ::com::sun::star::beans::IllegalTypeException + if the initial value is <NULL/> + @throws ::com::sun::star::beans::PropertyExistException + if the name or the handle are already used + @throws ::com::sun::star::beans::IllegalArgumentException + if the name is empty + */ + void addVoidProperty( + const OUString& _rName, + const ::com::sun::star::uno::Type& _rType, + sal_Int32 _nHandle, + sal_Int32 _nAttributes + ); + + /** removes a property from the bag + @param _rName + the name of the to-be-removed property. + @throws UnknownPropertyException + if the bag does not contain a property with the given name + @throws NotRemoveableException + if the property with the given name is not removeable, as indicated + by the property attributes used in a previous <code>addProperty</code> + call. + */ + void removeProperty( + const OUString& _rName + ); + + /** describes all properties in the bag + @param _out_rProps + takes, upon return, the descriptions of all properties in the bag + */ + inline void describeProperties( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _out_rProps + ) const + { + OPropertyContainerHelper::describeProperties( _out_rProps ); + } + + /** retrieves the value of a property given by handle + @param _nHandle + the handle of the property whose value is to be retrieved + @param _out_rValue + output parameter taking the property value + @throws UnknownPropertyException + if the given handle does not denote a property in the bag + */ + void getFastPropertyValue( + sal_Int32 _nHandle, + ::com::sun::star::uno::Any& _out_rValue + ) const; + + /** converts a to-be-set value of a property (given by handle) so that it can + be used in subsequent calls to setFastPropertyValue + @param _nHandle + the handle of the property + @param _rNewValue + the new value, which should be converted + @param _out_rConvertedValue + output parameter taking the converted value + @param _out_rCurrentValue + output parameter taking the current value of the + property + @throws UnknownPropertyException + if the given handle does not denote a property in the bag + @throws IllegalArgumentException + if the given value cannot be lossless converted into a value + for the given property. + */ + bool convertFastPropertyValue( + sal_Int32 _nHandle, + const ::com::sun::star::uno::Any& _rNewValue, + ::com::sun::star::uno::Any& _out_rConvertedValue, + ::com::sun::star::uno::Any& _out_rCurrentValue + ) const; + + /** sets a new value for a property given by handle + @throws UnknownPropertyException + if the given handle does not denote a property in the bag + */ + void setFastPropertyValue( + sal_Int32 _nHandle, + const ::com::sun::star::uno::Any& _rValue + ); + + /** returns the default value for a property given by handle + + The default value of a property is its initial value, as passed + to ->addProperty. + + @param _nHandle + handle of the property whose default value is to be obtained + @param _out_rValue + the default value + @throws UnknownPropertyException + if the given handle does not denote a property in the bag + */ + void getPropertyDefaultByHandle( + sal_Int32 _nHandle, + ::com::sun::star::uno::Any& _out_rValue + ) const; + + /** determines whether a property with a given name is part of the bag + */ + inline bool hasPropertyByName( const OUString& _rName ) const + { + return isRegisteredProperty( _rName ); + } + + /** determines whether a property with a given handle is part of the bag + */ + inline bool hasPropertyByHandle( sal_Int32 _nHandle ) const + { + return isRegisteredProperty( _nHandle ); + } + protected: + using OPropertyContainerHelper::convertFastPropertyValue; + using OPropertyContainerHelper::getFastPropertyValue; + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_PROPERTYBAG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertycontainer.hxx b/include/comphelper/propertycontainer.hxx new file mode 100644 index 000000000000..3d208413a722 --- /dev/null +++ b/include/comphelper/propertycontainer.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_ +#define _COMPHELPER_PROPERTYCONTAINER_HXX_ + +#include <comphelper/propertycontainerhelper.hxx> +#include <cppuhelper/propshlp.hxx> +#include <com/sun/star/uno/Type.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//========================================================================== +//= OPropertyContainer +//========================================================================== +typedef ::cppu::OPropertySetHelper OPropertyContainer_Base; +/** a OPropertySetHelper implementation which is just a simple container for properties represented + by class members, usually in a derived class. + <BR> + A restriction of this class is that no value conversions are made on a setPropertyValue call. Though + the base class supports this with the convertFastPropertyValue method, the OPropertyContainer accepts only + values which already have the correct type, it's unable to convert, for instance, a long to a short. +*/ +class COMPHELPER_DLLPUBLIC OPropertyContainer + :public OPropertyContainer_Base + ,public OPropertyContainerHelper +{ +public: + // this dtor is needed otherwise we can get a wrong delete operator + virtual ~OPropertyContainer(); + +protected: + OPropertyContainer(::cppu::OBroadcastHelper& _rBHelper); + + /// for scripting : the types of the interfaces supported by this class + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); + +// OPropertySetHelper overridables + 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); + + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) + throw (::com::sun::star::uno::Exception); + + using OPropertyContainer_Base::getFastPropertyValue; + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, + sal_Int32 nHandle + ) const; + + // disambiguate a base class method (XFastPropertySet) + virtual void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) + 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); +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTYCONTAINER_HXX_ + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertycontainerhelper.hxx b/include/comphelper/propertycontainerhelper.hxx new file mode 100644 index 000000000000..dacefd8737a6 --- /dev/null +++ b/include/comphelper/propertycontainerhelper.hxx @@ -0,0 +1,203 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_PROPERTYCONTAINERHELPER_HXX +#define COMPHELPER_PROPERTYCONTAINERHELPER_HXX + +#include <cppuhelper/propshlp.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/beans/Property.hpp> +#include <vector> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +// infos about one single property +struct COMPHELPER_DLLPUBLIC PropertyDescription +{ + // the possibilities where a property holding object may be located + enum LocationType + { + ltDerivedClassRealType, // within the derived class, it's a "real" (non-Any) type + ltDerivedClassAnyType, // within the derived class, it's a <type scope="com.sun.star.uno">Any</type> + ltHoldMyself // within m_aHoldProperties + }; + // the location of an object holding a property value : + union LocationAccess + { + void* pDerivedClassMember; // a pointer to a member of an object of a derived class + sal_Int32 nOwnClassVectorIndex; // an index within m_aHoldProperties + }; + + ::com::sun::star::beans::Property + aProperty; + LocationType eLocated; // where is the object containing the value located ? + LocationAccess aLocation; // access to the property value + + PropertyDescription() + :aProperty( OUString(), -1, ::com::sun::star::uno::Type(), 0 ) + ,eLocated( ltHoldMyself ) + { + aLocation.nOwnClassVectorIndex = -1; + } +}; + +//========================================================================== +//= OPropertyContainerHelper +//========================================================================== +/** helper class for managing property values, and implementing most of the X*Property* interfaces + + The property values are usually held in derived classes, but can also be given to the + responsibility of this class here. + + For more information, see http://wiki.services.openoffice.org/wiki/Development/Cpp/Helper/PropertyContainerHelper. +*/ +class COMPHELPER_DLLPUBLIC OPropertyContainerHelper +{ + typedef ::std::vector< ::com::sun::star::uno::Any > PropertyContainer; + typedef PropertyContainer::iterator PropertyContainerIterator; + typedef PropertyContainer::const_iterator ConstPropertyContainerIterator; + PropertyContainer m_aHoldProperties; + // the properties which are hold by this class' instance, not the derived one's + +private: + typedef ::std::vector< PropertyDescription > Properties; + typedef Properties::iterator PropertiesIterator; + typedef Properties::const_iterator ConstPropertiesIterator; + Properties m_aProperties; + + sal_Bool m_bUnused; + +protected: + OPropertyContainerHelper(); + ~OPropertyContainerHelper(); + + /** register a property. The property is represented through a member of the derived class which calls + this methdod. + @param _rName the name of the property + @param _nHandle the handle of the property + @param _nAttributes the attributes of the property + @param _pPointerToMember the pointer to the member representing the property + within the derived class. + @param _rMemberType the cppu type of the property represented by the object + to which _pPointerToMember points. + */ + void registerProperty(const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + void* _pPointerToMember, const ::com::sun::star::uno::Type& _rMemberType); + + + /** register a property. The property is represented through a ::com::sun::star::uno::Any member of the + derived class which calls this methdod. + @param _rName the name of the property + @param _nHandle the handle of the property + @param _nAttributes the attributes of the property + @param _pPointerToMember the pointer to the member representing the property + within the derived class, which has to be a ::com::sun::star::uno::Any. + @param _rExpectedType the expected type of the property. NOT the type of the object to which + _pPointerToMember points (this is always an Any). + */ + void registerMayBeVoidProperty(const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + ::com::sun::star::uno::Any* _pPointerToMember, const ::com::sun::star::uno::Type& _rExpectedType); + + /** register a property. The repository will create an own object holding this property, so there is no + need to declare an extra member in your derived class + @param _rName the name of the property + @param _nHandle the handle of the property + @param _nAttributes the attributes of the property + @param _rType the type of the property + @param _pInitialValue the initial value of the property. May be null if _nAttributes includes + the ::com::sun::star::beans::PropertyAttribute::MAYBEVOID flag. + Else it must be a pointer to an object of the type described by _rType. + */ + void registerPropertyNoMember(const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + const ::com::sun::star::uno::Type& _rType, const void* _pInitialValue); + + /** revokes a previously registered property + @throw com::sun::star::beans::UnknownPropertyException + if no property with the given handle is registered + */ + void revokeProperty( sal_Int32 _nHandle ); + + + /// checkes whether a property with the given handle has been registered + sal_Bool isRegisteredProperty( sal_Int32 _nHandle ) const; + + /// checkes whether a property with the given name has been registered + sal_Bool isRegisteredProperty( const OUString& _rName ) const; + + + // helper for implementing OPropertySetHelper overridables + sal_Bool convertFastPropertyValue( + ::com::sun::star::uno::Any & rConvertedValue, + ::com::sun::star::uno::Any & rOldValue, + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) + SAL_THROW((::com::sun::star::lang::IllegalArgumentException)); + + void setFastPropertyValue( + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) + SAL_THROW((::com::sun::star::uno::Exception)); + + void getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, + sal_Int32 nHandle + ) const; + +// helper + /** appends the descriptions of all properties which were registered 'til that moment to the given sequence, + keeping the array sorted (by name) + @precond + the given sequence is already sorted by name + @param _rProps + initial property sequence which is to be extended + */ + void describeProperties(::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps) const; + + /** retrieves the description for a registered property + @throw com::sun::star::beans::UnknownPropertyException + if no property with the given name is registered + */ + const ::com::sun::star::beans::Property& + getProperty( const OUString& _rName ) const; + +private: + /// insertion of _rProp into m_aProperties, keeping the sort order + COMPHELPER_DLLPRIVATE void implPushBackProperty(const PropertyDescription& _rProp); + + /// search the PropertyDescription for the given handle (within m_aProperties) + COMPHELPER_DLLPRIVATE PropertiesIterator searchHandle(sal_Int32 _nHandle); + +private: + COMPHELPER_DLLPRIVATE OPropertyContainerHelper( const OPropertyContainerHelper& ); // never implemented + COMPHELPER_DLLPRIVATE OPropertyContainerHelper& operator=( const OPropertyContainerHelper& ); // never implemented +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_PROPERTYCONTAINERHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertysethelper.hxx b/include/comphelper/propertysethelper.hxx new file mode 100644 index 000000000000..ecc600c37d3c --- /dev/null +++ b/include/comphelper/propertysethelper.hxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTYSETHELPER_HXX_ +#define _COMPHELPER_PROPERTYSETHELPER_HXX_ + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include "comphelper/comphelperdllapi.h" + +//========================================================================= +//= property helper classes +//========================================================================= + +//... namespace comphelper ................................................ +namespace comphelper +{ +//......................................................................... + +class PropertySetInfo; +struct PropertyMapEntry; +class PropertySetHelperImpl; + +class COMPHELPER_DLLPUBLIC PropertySetHelper : public ::com::sun::star::beans::XPropertySet, + public ::com::sun::star::beans::XPropertyState, + public ::com::sun::star::beans::XMultiPropertySet +{ +private: + PropertySetHelperImpl* mp; + +protected: + virtual void _setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const ::com::sun::star::uno::Any* pValues ) 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 ) = 0; + virtual void _getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, ::com::sun::star::uno::Any* pValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ) = 0; + + virtual void _getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, ::com::sun::star::beans::PropertyState* pStates ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException ); + virtual void _setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Any _getPropertyDefault( const comphelper::PropertyMapEntry* pEntry ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); + +public: + PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw(); + PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw(); + virtual ~PropertySetHelper() throw(); + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 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); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + // XMultiPropertySet +// virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePropertiesChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL firePropertiesChangeEvent( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertiesChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); + + // XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > SAL_CALL getPropertyStates( const ::com::sun::star::uno::Sequence< OUString >& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); +}; + +//......................................................................... +} +//... namespace comphelper.................................................. + +#endif // _UTL_PROPERTYSETHELPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertysetinfo.hxx b/include/comphelper/propertysetinfo.hxx new file mode 100644 index 000000000000..e0b863e8f2ca --- /dev/null +++ b/include/comphelper/propertysetinfo.hxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTSETINFO_HXX_ +#define _COMPHELPER_PROPERTSETINFO_HXX_ + +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/stl_types.hxx> +#include "comphelper/comphelperdllapi.h" + +//========================================================================= +//= property helper classes +//========================================================================= + +//... namespace comphelper ....................................................... +namespace comphelper +{ +//......................................................................... + +struct PropertyMapEntry +{ + const sal_Char* mpName; + sal_uInt16 mnNameLen; + sal_Int32 mnHandle; + const com::sun::star::uno::Type* mpType; + sal_Int16 mnAttributes; + sal_uInt8 mnMemberId; +}; + +DECLARE_STL_USTRINGACCESS_MAP( PropertyMapEntry*, PropertyMap ); + +class PropertyMapImpl; + +/** this class implements a XPropertySetInfo that is initialized with arrays of PropertyMapEntry. + It is used by the class PropertySetHelper. +*/ +class COMPHELPER_DLLPUBLIC PropertySetInfo : public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo > +{ +private: + PropertyMapImpl* mpMap; +public: + PropertySetInfo() throw(); + PropertySetInfo( PropertyMapEntry* pMap ) throw(); + virtual ~PropertySetInfo() throw(); + + /** returns a stl map with all PropertyMapEntry pointer.<p> + The key is the property name. + */ + const PropertyMap* getPropertyMap() const throw(); + + /** adds an array of PropertyMapEntry to this instance.<p> + The end is marked with a PropertyMapEntry where mpName equals NULL</p> + */ + void add( PropertyMapEntry* pMap ) throw(); + + /** removes an already added PropertyMapEntry which string in mpName equals to aName */ + void remove( const OUString& aName ) throw(); + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties() throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw(::com::sun::star::uno::RuntimeException); +}; + +//......................................................................... +} +//... namespace comphelper ....................................................... + +#endif // _UTL_PROPERTSETINFO_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertystatecontainer.hxx b/include/comphelper/propertystatecontainer.hxx new file mode 100644 index 000000000000..acd368646628 --- /dev/null +++ b/include/comphelper/propertystatecontainer.hxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_PROPERTYSTATECONTAINER_HXX +#define COMPHELPER_PROPERTYSTATECONTAINER_HXX + +#include <comphelper/propertycontainer.hxx> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/uno3.hxx> +#include <osl/diagnose.h> +#include "comphelper/comphelperdllapi.h" + +#include <map> + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= OPropertyStateContainer + //===================================================================== + typedef ::cppu::ImplHelper1 < ::com::sun::star::beans::XPropertyState + > OPropertyStateContainer_TBase; + + /** helper implementation for components which have properties with a default + + <p>This class is not intended for direct use, you need to derive from it.</p> + + @see com.sun.star.beans.XPropertyState + */ + class COMPHELPER_DLLPUBLIC OPropertyStateContainer + :public OPropertyContainer + ,public OPropertyStateContainer_TBase + { + protected: + /** ctor + @param _rBHelper + help to be used for broadcasting events + */ + OPropertyStateContainer( ::cppu::OBroadcastHelper& _rBHelper ); + + // ................................................................ + // XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > SAL_CALL getPropertyStates( const ::com::sun::star::uno::Sequence< OUString >& aPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + // ................................................................ + // own overridables + // these are the impl-methods for the XPropertyState members - they are implemented already by this class, + // but you may want to override them for whatever reasons (for instance, if your derived class + // supports the AMBIGUOUS state for properties) + + /** get the PropertyState of the property denoted by the given handle + + <p>Already implemented by this base class, no need to override</p> + @precond <arg>_nHandle</arg> is a valid property handle + */ + virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle( sal_Int32 _nHandle ); + + /** set the property denoted by the given handle to it's default value + + <p>Already implemented by this base class, no need to override</p> + @precond <arg>_nHandle</arg> is a valid property handle + */ + virtual void setPropertyToDefaultByHandle( sal_Int32 _nHandle ); + + /** get the default value for the property denoted by the given handle + + @precond + <arg>_nHandle</arg> is a valid property handle + */ + virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle, ::com::sun::star::uno::Any& _rDefault ) const = 0; + + protected: + // XInterface + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException); + // XTypeProvider + DECLARE_XTYPEPROVIDER( ) + + protected: + /** returns the handle for the given name + + @throw UnknownPropertyException if the given name is not a registered property + */ + sal_Int32 getHandleForName( const OUString& _rPropertyName ) SAL_THROW( ( ::com::sun::star::beans::UnknownPropertyException ) ); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_PROPERTYSTATECONTAINER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propmultiplex.hxx b/include/comphelper/propmultiplex.hxx new file mode 100644 index 000000000000..28795e57ce8a --- /dev/null +++ b/include/comphelper/propmultiplex.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ +#define _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ + +#include <comphelper/propstate.hxx> +#include <cppuhelper/implbase1.hxx> +#include "comphelper/comphelperdllapi.h" + +//========================================================================= +//= property helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + class OPropertyChangeMultiplexer; + + //================================================================== + //= OPropertyChangeListener + //================================================================== + /// simple listener adapter for property sets + class COMPHELPER_DLLPUBLIC OPropertyChangeListener + { + friend class OPropertyChangeMultiplexer; + + OPropertyChangeMultiplexer* m_pAdapter; + ::osl::Mutex& m_rMutex; + + public: + OPropertyChangeListener(::osl::Mutex& _rMutex) + : m_pAdapter(NULL), m_rMutex(_rMutex) { } + virtual ~OPropertyChangeListener(); + + virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& _rEvent) throw( ::com::sun::star::uno::RuntimeException) = 0; + virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException); + + protected: + /** If the derivee also owns the mutex which we know as reference, then call this within your + derivee's dtor. + */ + void disposeAdapter(); + + // pseudo-private. Making it private now could break compatibility + void setAdapter( OPropertyChangeMultiplexer* _pAdapter ); + }; + + //================================================================== + //= OPropertyChangeMultiplexer + //================================================================== + /// multiplexer for property changes + class COMPHELPER_DLLPUBLIC OPropertyChangeMultiplexer :public cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertyChangeListener> + { + friend class OPropertyChangeListener; + ::com::sun::star::uno::Sequence< OUString > m_aProperties; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xSet; + OPropertyChangeListener* m_pListener; + sal_Int32 m_nLockCount; + sal_Bool m_bListening : 1; + sal_Bool m_bAutoSetRelease : 1; + + + virtual ~OPropertyChangeMultiplexer(); + public: + OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException); + + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException); + + /// incremental lock + void lock(); + /// incremental unlock + void unlock(); + /// get the lock count + sal_Int32 locked() const { return m_nLockCount; } + + void addProperty(const OUString& aPropertyName); + void dispose(); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propstate.hxx b/include/comphelper/propstate.hxx new file mode 100644 index 000000000000..727f40d96824 --- /dev/null +++ b/include/comphelper/propstate.hxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_PROPERTY_STATE_HXX_ +#define _COMPHELPER_PROPERTY_STATE_HXX_ + +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/uno/Sequence.hxx> + + +#include <cppuhelper/propshlp.hxx> +#include <cppuhelper/proptypehlp.hxx> +#include <cppuhelper/weak.hxx> +#include <comphelper/uno3.hxx> +#include <comphelper/broadcasthelper.hxx> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include "comphelper/comphelperdllapi.h" + +//========================================================================= +//= property helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //================================================================== + //= OPropertyStateHelper + //================================================================== + /// helper class for implementing property states + class COMPHELPER_DLLPUBLIC OPropertyStateHelper :public ::cppu::OPropertySetHelper2 + ,public ::com::sun::star::beans::XPropertyState + { + public: + OPropertyStateHelper(::cppu::OBroadcastHelper& rBHlp):OPropertySetHelper2(rBHlp) { } + OPropertyStateHelper(::cppu::OBroadcastHelper& rBHlp, + ::cppu::IEventNotificationHook *i_pFireEvents); + + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& aType) throw(::com::sun::star::uno::RuntimeException); + + // XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL + getPropertyState(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> SAL_CALL + getPropertyStates(const ::com::sun::star::uno::Sequence< OUString >& aPropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL + setPropertyToDefault(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL + getPropertyDefault(const OUString& aPropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + // access via handle + virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle(sal_Int32 nHandle); + virtual void setPropertyToDefaultByHandle(sal_Int32 nHandle); + virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const; + + protected: + virtual ~OPropertyStateHelper(); + + void firePropertyChange(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aNewValue, const ::com::sun::star::uno::Any& aOldValue); + + protected: + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL getTypes() throw(::com::sun::star::uno::RuntimeException); + }; + + //================================================================== + //= OPropertyStateHelper + //================================================================== + class COMPHELPER_DLLPUBLIC OStatefulPropertySet :public ::cppu::OWeakObject + ,public ::com::sun::star::lang::XTypeProvider + ,public OMutexAndBroadcastHelper // order matters: before OPropertyStateHelper/OPropertySetHelper + ,public OPropertyStateHelper + { + protected: + OStatefulPropertySet(); + virtual ~OStatefulPropertySet(); + + protected: + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_STATE_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/proxyaggregation.hxx b/include/comphelper/proxyaggregation.hxx new file mode 100644 index 000000000000..2c01a7a3587f --- /dev/null +++ b/include/comphelper/proxyaggregation.hxx @@ -0,0 +1,221 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_PROXY_AGGREGATION +#define COMPHELPER_PROXY_AGGREGATION + +#include <com/sun/star/uno/XAggregation.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/interfacecontainer.hxx> +#include <comphelper/uno3.hxx> +#include <comphelper/broadcasthelper.hxx> +#include <cppuhelper/compbase_ex.hxx> +#include "comphelper/comphelperdllapi.h" + +/* class hierarchy herein: + + +-------------------+ helper class for aggregating the proxy to another object + | OProxyAggregation | - not ref counted + +-------------------+ - no UNO implementation, i.e. not derived from XInterface + ^ (neither direct nor indirect) + | + | + +----------------------------------+ helper class for aggregating a proxy to an XComponent + | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate") + +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and + ^ vice versa + | - UNO based, implementing XEventListener + | + +----------------------------+ component aggregating another XComponent + | OComponentProxyAggregation | - life time coupling as above + +----------------------------+ - ref-counted + - implements an XComponent itself + + If you need to + + - wrap a foreign object which is a XComponent + => use OComponentProxyAggregation + - call componentAggregateProxyFor in your ctor + - call implEnsureDisposeInDtor in your dtor + + - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms + inherited from somewhere else + => use OComponentProxyAggregationHelper + - override dispose - don't forget to call the base class' dispose! + - call componentAggregateProxyFor in your ctor + + - wrap a foreign object which is no XComponent + => use OProxyAggregation + - call baseAggregateProxyFor in your ctor +*/ + +//............................................................................. +namespace comphelper +{ +//............................................................................. + + //========================================================================= + //= OProxyAggregation + //========================================================================= + /** helper class for aggregating a proxy for a foreign object + */ + class OProxyAggregation + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xProxyAggregate; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider > m_xProxyTypeAccess; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + + protected: + inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getComponentContext() + { + return m_xContext; + } + + protected: + OProxyAggregation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext ); + ~OProxyAggregation(); + + /// to be called from within your ctor + void baseAggregateProxyFor( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, + oslInterlockedCount& _rRefCount, + ::cppu::OWeakObject& _rDelegator + ); + + // XInterface and XTypeProvider + ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException); + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); + + private: + OProxyAggregation( ); // never implemented + OProxyAggregation( const OProxyAggregation& ); // never implemented + OProxyAggregation& operator=( const OProxyAggregation& ); // never implemented + }; + + //========================================================================= + //= OComponentProxyAggregationHelper + //========================================================================= + /** a helper class for aggregating a proxy to an XComponent + + <p>The object couples the life time of itself and the component: if one of the both + dies (in a sense of being disposed), the other one dies, too.</p> + + <p>The class itself does not implement XComponent so you need to forward any XComponent::dispose + calls which your derived class gets to the dispose method of this class.</p> + */ + + class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 < com::sun::star::lang::XEventListener + > + ,private OProxyAggregation + { + private: + typedef ::cppu::ImplHelper1 < ::com::sun::star::lang::XEventListener + > BASE; // prevents some MSVC problems + + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + m_xInner; + ::cppu::OBroadcastHelper& m_rBHelper; + + protected: + // OProxyAggregation + using OProxyAggregation::getComponentContext; + + // XInterface + ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException); + + // XTypeProvider + DECLARE_XTYPEPROVIDER( ) + + protected: + OComponentProxyAggregationHelper( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + ::cppu::OBroadcastHelper& _rBHelper + ); + virtual ~OComponentProxyAggregationHelper( ); + + /// to be called from within your ctor + void componentAggregateProxyFor( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent, + oslInterlockedCount& _rRefCount, + ::cppu::OWeakObject& _rDelegator + ); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); + + private: + COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( ); // never implemented + COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ); // never implemented + COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ); // never implemented + }; + + //========================================================================= + //= OComponentProxyAggregation + //========================================================================= + class COMPHELPER_DLLPUBLIC OComponentProxyAggregation :public OBaseMutex + ,public cppu::WeakComponentImplHelperBase + ,public OComponentProxyAggregationHelper + { + protected: + OComponentProxyAggregation( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent + ); + + virtual ~OComponentProxyAggregation(); + + // XInterface + DECLARE_XINTERFACE() + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // OComponentHelper + virtual void SAL_CALL disposing() throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent/OComponentProxyAggregationHelper + virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); + + protected: + // be called from within the dtor of derived classes + void implEnsureDisposeInDtor( ); + + private: + COMPHELPER_DLLPRIVATE OComponentProxyAggregation( ); // never implemented + COMPHELPER_DLLPRIVATE OComponentProxyAggregation( const OComponentProxyAggregation& ); // never implemented + COMPHELPER_DLLPRIVATE OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ); // never implemented + }; + +//............................................................................. +} // namespace comphelper +//............................................................................. + + +#endif // COMPHELPER_PROXY_AGGREGATION + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/scoped_disposing_ptr.hxx b/include/comphelper/scoped_disposing_ptr.hxx new file mode 100644 index 000000000000..dabf9f473e92 --- /dev/null +++ b/include/comphelper/scoped_disposing_ptr.hxx @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _SCOPED_DISPOSING_PTR +#define _SCOPED_DISPOSING_PTR + +#include <cppuhelper/implbase1.hxx> +#include <boost/utility.hpp> +#include <boost/scoped_ptr.hpp> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XDesktop.hpp> + +// for locking SolarMutex: svapp + mutex +#include <vcl/svapp.hxx> +#include <osl/mutex.hxx> + +namespace comphelper +{ +//Similar to boost::scoped_ptr, except additionally releases the ptr on XComponent::disposing and/or XTerminateListener::notifyTermination if supported +template<class T> class scoped_disposing_ptr : private boost::noncopyable +{ +private: + boost::scoped_ptr<T> m_aItem; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTerminateListener> m_xTerminateListener; +public: + scoped_disposing_ptr( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > &rComponent, T * p = 0 ) + : m_aItem(p) + { + m_xTerminateListener = new TerminateListener(rComponent, *this); + } + + virtual void reset(T * p = 0) + { + m_aItem.reset(p); + } + + T & operator*() const + { + return *m_aItem; + } + + T * get() const + { + return m_aItem.get(); + } + + T * operator->() const + { + return m_aItem.get(); + } + + operator bool () const + { + return static_cast< bool >(m_aItem); + } + + virtual ~scoped_disposing_ptr() + { + reset(); + } +private: + class TerminateListener : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XTerminateListener > + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xComponent; + scoped_disposing_ptr<T>& m_rItem; + public: + TerminateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > &rComponent, + scoped_disposing_ptr<T>& rItem) : m_xComponent(rComponent), m_rItem(rItem) + { + if (m_xComponent.is()) + { + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop> xDesktop(m_xComponent, ::com::sun::star::uno::UNO_QUERY); + if (xDesktop.is()) + xDesktop->addTerminateListener(this); + else + m_xComponent->addEventListener(this); + } + } + + ~TerminateListener() + { + if ( m_xComponent.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop> xDesktop(m_xComponent, ::com::sun::star::uno::UNO_QUERY); + if (xDesktop.is()) + xDesktop->removeTerminateListener(this); + else + m_xComponent->removeEventListener(this); + } + } + + private: + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& rEvt ) + throw (::com::sun::star::uno::RuntimeException) + { + bool shutDown = (rEvt.Source == m_xComponent); + + if (shutDown && m_xComponent.is()) + { + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop> xDesktop(m_xComponent, ::com::sun::star::uno::UNO_QUERY); + if (xDesktop.is()) + xDesktop->removeTerminateListener(this); + else + m_xComponent->removeEventListener(this); + m_xComponent.clear(); + } + + if (shutDown) + m_rItem.reset(); + } + + // XTerminateListener + virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& ) + throw(::com::sun::star::frame::TerminationVetoException, + ::com::sun::star::uno::RuntimeException) + { + } + + virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& rEvt ) + throw (::com::sun::star::uno::RuntimeException) + { + disposing(rEvt); + } + }; +}; + +//Something like an OutputDevice requires the SolarMutex to be taken before use +//for threadsafety. The user can ensure this, except in the case of its dtor +//being called from reset due to a terminate on the XComponent being called +//from an aribitrary thread +template<class T> class scoped_disposing_solar_mutex_reset_ptr + : public scoped_disposing_ptr<T> +{ +public: + scoped_disposing_solar_mutex_reset_ptr( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > &rComponent, T * p = 0 ) + : scoped_disposing_ptr<T>(rComponent, p) + { + } + + virtual void reset(T * p = 0) + { + SolarMutexGuard aGuard; + scoped_disposing_ptr<T>::reset(p); + } +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/scopeguard.hxx b/include/comphelper/scopeguard.hxx new file mode 100644 index 000000000000..5bc2aafaa781 --- /dev/null +++ b/include/comphelper/scopeguard.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef INCLUDED_COMPHELPER_SCOPEGUARD_HXX +#define INCLUDED_COMPHELPER_SCOPEGUARD_HXX + +#include "comphelper/comphelperdllapi.h" +#include "boost/function.hpp" +#include "boost/noncopyable.hpp" +#include "boost/bind.hpp" + +namespace comphelper { + +/** ScopeGuard to ease writing exception-safe code. + */ +class COMPHELPER_DLLPUBLIC ScopeGuard : private ::boost::noncopyable + // noncopyable until we have + // good reasons... +{ +public: + enum exc_handling { IGNORE_EXCEPTIONS, ALLOW_EXCEPTIONS }; + + /** @param func function object to be executed in dtor + @param excHandling switches whether thrown exceptions in dtor will be + silently ignored (but OSL_ asserted) + */ + template <typename func_type> + explicit ScopeGuard( func_type const & func, + exc_handling excHandling = IGNORE_EXCEPTIONS ) + : m_func( func ), m_excHandling( excHandling ) {} + + ~ScopeGuard(); + + /** Dismisses the scope guard, i.e. the function won't + be executed. + */ + void dismiss(); + +private: + ::boost::function0<void> m_func; // preferring portable syntax + exc_handling const m_excHandling; +}; + +} // namespace comphelper + +#endif // ! defined(INCLUDED_COMPHELPER_SCOPEGUARD_HXX) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/seekableinput.hxx b/include/comphelper/seekableinput.hxx new file mode 100644 index 000000000000..02c4997a2cb6 --- /dev/null +++ b/include/comphelper/seekableinput.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_STREAM_SEEKABLEINPUT_HXX_ +#define _COMPHELPER_STREAM_SEEKABLEINPUT_HXX_ + +#include <osl/mutex.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <cppuhelper/implbase2.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + +class COMPHELPER_DLLPUBLIC OSeekableInputWrapper : public ::cppu::WeakImplHelper2< ::com::sun::star::io::XInputStream, + ::com::sun::star::io::XSeekable > +{ + ::osl::Mutex m_aMutex; + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xOriginalStream; + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xCopyInput; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xCopySeek; + +private: + COMPHELPER_DLLPRIVATE void PrepareCopy_Impl(); + +public: + OSeekableInputWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); + + virtual ~OSeekableInputWrapper(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > CheckSeekableCanWrap( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); + +// XInputStream + virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL available() throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL closeInput() throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + +// XSeekable + virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + +}; + +} // namespace comphelper + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/seqstream.hxx b/include/comphelper/seqstream.hxx new file mode 100644 index 000000000000..4f9c9380bfa1 --- /dev/null +++ b/include/comphelper/seqstream.hxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_SEQSTREAM_HXX +#define _COMPHELPER_SEQSTREAM_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <osl/mutex.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + + typedef ::com::sun::star::uno::Sequence<sal_Int8> ByteSequence; + +//================================================================== +// SequenceInputStream +// stream for reading data from a sequence of bytes +//================================================================== + + +class COMPHELPER_DLLPUBLIC SequenceInputStream +: public ::cppu::WeakImplHelper2< ::com::sun::star::io::XInputStream, ::com::sun::star::io::XSeekable > +{ + ::osl::Mutex m_aMutex; + ByteSequence m_aData; + sal_Int32 m_nPos; + +public: + SequenceInputStream(const ByteSequence& rData); + +// com::sun::star::io::XInputStream + virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL available( ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL closeInput( ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + +private: + inline sal_Int32 avail(); +}; +typedef ::cppu::WeakImplHelper1< ::com::sun::star::io::XOutputStream > OSequenceOutputStream_Base; + +class OSequenceOutputStream : public OSequenceOutputStream_Base +{ +protected: + ::com::sun::star::uno::Sequence< sal_Int8 >& m_rSequence; + double m_nResizeFactor; + sal_Int32 m_nMinimumResize; + sal_Int32 m_nMaximumResize; + sal_Int32 m_nSize; + // the size of the virtual stream. This is not the size of the sequence, but the number of bytes written + // into the stream at a given moment. + + sal_Bool m_bConnected; + // closeOutput has been called ? + + ::osl::Mutex m_aMutex; + +protected: + ~OSequenceOutputStream() { if (m_bConnected) closeOutput(); } + +public: + /** constructs the object. Everything written into the stream through the XOutputStream methods will be forwarded + to the sequence, reallocating it if neccessary. Writing will start at offset 0 within the sequence. + @param _rSeq a reference to the sequence which will be used for output. + The caller is responsible for taking care of the lifetime of the stream + object and the sequence. If you're in doubt about this, use <code>closeOutput</code> + before destroying the sequence + @param _nResizeFactor the factor which is used for resizing the sequence when neccessary. In every + resize step, the new sequence size will be calculated by multiplying the current + size with this factor, rounded off to the next multiple of 4. + @param _nMinimumResize the minmal number of bytes which is additionally allocated on resizing + @param _nMaximumResize as the growth of the stream size is exponential, you may want to specify a + maxmimum amount of memory which the sequence will grow by. If -1 is used, + no limit is applied + @see closeOutput + */ + OSequenceOutputStream( + ::com::sun::star::uno::Sequence< sal_Int8 >& _rSeq, + double _nResizeFactor = 1.3, + sal_Int32 _nMinimumResize = 128, + sal_Int32 _nMaximumResize = -1 + ); + + /// same as XOutputStream::writeBytes (as expected :) + virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + /// this is a dummy in this implementation, no buffering is used + virtual void SAL_CALL flush( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + /** closes the output stream. In the case of this class, this means that the sequence used for writing is + resized to the really used size and not used any further, every subsequent call to one of the XOutputStream + methods will throw a <code>NotConnectedException</code>. + */ + virtual void SAL_CALL closeOutput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); +}; + +} // namespace comphelper + +#endif //_COMPHELPER_SEQSTREAM_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/sequence.hxx b/include/comphelper/sequence.hxx new file mode 100644 index 000000000000..ad1e8943b952 --- /dev/null +++ b/include/comphelper/sequence.hxx @@ -0,0 +1,369 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_SEQUENCE_HXX_ +#define _COMPHELPER_SEQUENCE_HXX_ + +#include <algorithm> // copy algorithm +#include <com/sun/star/uno/Sequence.hxx> +#include <osl/diagnose.h> +#include "comphelper/comphelperdllapi.h" + +#include <vector> + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + + //------------------------------------------------------------------------- + /** search the given string within the given sequence, return the positions where it was found. + if _bOnlyFirst is sal_True, only the first occurrence will be returned. + */ + COMPHELPER_DLLPUBLIC staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< OUString >& _rList, const OUString& _rValue, sal_Bool _bOnlyFirst = sal_False); + + /** Checks if the name exists + * + * \param Value The value to search for. + * \param _aList The list in which to search for the value. + * \return <TRUE/> if the value can be found, otherwise <FALSE/>. + */ + COMPHELPER_DLLPUBLIC sal_Bool existsValue(const OUString& Value,const ::com::sun::star::uno::Sequence< OUString >& _aList); + + + //------------------------------------------------------------------------- + namespace internal + { + template <class T> + void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen) + { + for (sal_Int32 i=0; i<_nSourceLen; ++i, ++_pSource, ++_pDest) + *_pDest = *_pSource; + } + } + //------------------------------------------------------------------------- + /// concat two sequences + template <class T> + staruno::Sequence<T> concatSequences(const staruno::Sequence<T>& _rLeft, const staruno::Sequence<T>& _rRight) + { + sal_Int32 nLeft(_rLeft.getLength()), nRight(_rRight.getLength()); + const T* pLeft = _rLeft.getConstArray(); + const T* pRight = _rRight.getConstArray(); + + sal_Int32 nReturnLen(nLeft + nRight); + staruno::Sequence<T> aReturn(nReturnLen); + T* pReturn = aReturn.getArray(); + + internal::implCopySequence(pLeft, pReturn, nLeft); + internal::implCopySequence(pRight, pReturn, nRight); + + return aReturn; + } + + //------------------------------------------------------------------------- + /// concat three sequences + template <class T> + staruno::Sequence<T> concatSequences(const staruno::Sequence<T>& _rLeft, const staruno::Sequence<T>& _rMiddle, const staruno::Sequence<T>& _rRight) + { + sal_Int32 nLeft(_rLeft.getLength()), nMiddle(_rMiddle.getLength()), nRight(_rRight.getLength()); + const T* pLeft = _rLeft.getConstArray(); + const T* pMiddle = _rMiddle.getConstArray(); + const T* pRight = _rRight.getConstArray(); + + sal_Int32 nReturnLen(nLeft + nMiddle + nRight); + staruno::Sequence<T> aReturn(nReturnLen); + T* pReturn = aReturn.getArray(); + + internal::implCopySequence(pLeft, pReturn, nLeft); + internal::implCopySequence(pMiddle, pReturn, nMiddle); + internal::implCopySequence(pRight, pReturn, nRight); + + return aReturn; + } + + //------------------------------------------------------------------------- + /// remove a specified element from a sequences + template<class T> + void removeElementAt(staruno::Sequence<T>& _rSeq, sal_Int32 _nPos) + { + sal_uInt32 nLength = _rSeq.getLength(); + + OSL_ENSURE(0 <= _nPos && (sal_uInt32)_nPos < nLength, "invalid index"); + + for (sal_uInt32 i = (sal_uInt32)_nPos + 1; i < nLength; ++i) + { + _rSeq[i-1] = _rSeq[i]; + } + + _rSeq.realloc(nLength-1); + } + + //===================================================================== + //= iterating through sequences + //===================================================================== + /** a helper class for iterating through a sequence + */ + template <class TYPE> + class OSequenceIterator + { + const TYPE* m_pElements; + sal_Int32 m_nLen; + const TYPE* m_pCurrent; + + public: + /** contrcuct a sequence iterator from a sequence + */ + OSequenceIterator(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq); + /** contrcuct a sequence iterator from a Any containing a sequence + */ + OSequenceIterator(const ::com::sun::star::uno::Any& _rSequenceAny); + + sal_Bool hasMoreElements() const; + ::com::sun::star::uno::Any nextElement(); + + private: + void construct(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq); + }; + + //--------------------------------------------------------------------- + template <class TYPE> + OSequenceIterator<TYPE>::OSequenceIterator(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq) + :m_pElements(NULL) + ,m_nLen(0) + ,m_pCurrent(NULL) + { + construct(_rSeq); + } + + //--------------------------------------------------------------------- + template <class TYPE> + OSequenceIterator<TYPE>::OSequenceIterator(const ::com::sun::star::uno::Any& _rSequenceAny) + :m_pElements(NULL) + ,m_nLen(0) + ,m_pCurrent(NULL) + { + ::com::sun::star::uno::Sequence< TYPE > aContainer; + sal_Bool bSuccess = _rSequenceAny >>= aContainer; + OSL_ENSURE(bSuccess, "OSequenceIterator::OSequenceIterator: invalid Any!"); + (void)bSuccess; + construct(aContainer); + } + + //--------------------------------------------------------------------- + template <class TYPE> + void OSequenceIterator<TYPE>::construct(const ::com::sun::star::uno::Sequence< TYPE >& _rSeq) + { + m_pElements = _rSeq.getConstArray(); + m_nLen = _rSeq.getLength(); + m_pCurrent = m_pElements; + } + + //--------------------------------------------------------------------- + template <class TYPE> + sal_Bool OSequenceIterator<TYPE>::hasMoreElements() const + { + return m_pCurrent - m_pElements < m_nLen; + } + + //--------------------------------------------------------------------- + template <class TYPE> + ::com::sun::star::uno::Any OSequenceIterator<TYPE>::nextElement() + { + return ::com::sun::star::uno::makeAny(*m_pCurrent++); + } + + //------------------------------------------------------------------------- + /** Copy from a plain C/C++ array into a Sequence. + + @tpl SrcType + Array element type. Must be assignable to DstType + + @tpl DstType + Sequence element type. Must be assignable from SrcType + + @param i_pArray + Valid pointer to at least num elements of type SrcType + + @param nNum + Number of array elements to copy + + @return the resulting Sequence + + @attention when copying from e.g. a double array to a + Sequence<int>, no proper rounding will be performed, but the + values will be truncated. There's currently no measure to + prevent or detect precision loss, overflow or truncation. + */ + template < typename DstType, typename SrcType > + ::com::sun::star::uno::Sequence< DstType > arrayToSequence( const SrcType* i_pArray, sal_Int32 nNum ) + { + ::com::sun::star::uno::Sequence< DstType > result( nNum ); + ::std::copy( i_pArray, i_pArray+nNum, result.getArray() ); + return result; + } + + //------------------------------------------------------------------------- + /** Copy from a Sequence into a plain C/C++ array + + @tpl SrcType + Sequence element type. Must be assignable to DstType + + @tpl DstType + Array element type. Must be assignable from SrcType + + @param io_pArray + Valid pointer to at least i_Sequence.getLength() elements of + type DstType + + @param i_Sequence + Reference to a Sequence of SrcType elements + + @return a pointer to the array + + @attention when copying from e.g. a Sequence<double> to an int + array, no proper rounding will be performed, but the values + will be truncated. There's currently no measure to prevent or + detect precision loss, overflow or truncation. + */ + template < typename DstType, typename SrcType > + DstType* sequenceToArray( DstType* io_pArray, const ::com::sun::star::uno::Sequence< SrcType >& i_Sequence ) + { + ::std::copy( i_Sequence.getConstArray(), i_Sequence.getConstArray()+i_Sequence.getLength(), io_pArray ); + return io_pArray; + } + + //------------------------------------------------------------------------- + /** Copy from a container into a Sequence + + @tpl SrcType + Container type. This type must fulfill the STL container + concept, in particular, the size(), begin() and end() methods + must be available and have the usual semantics. + + @tpl DstType + Sequence element type. Must be assignable from SrcType's + elements + + @param i_Container + Reference to the input contain with elements of type SrcType + + @return the generated Sequence + + @attention this function always performs a copy. Furthermore, + when copying from e.g. a vector<double> to a Sequence<int>, no + proper rounding will be performed, but the values will be + truncated. There's currently no measure to prevent or detect + precision loss, overflow or truncation. + */ + template < typename DstType, typename SrcType > + ::com::sun::star::uno::Sequence< DstType > containerToSequence( const SrcType& i_Container ) + { + ::com::sun::star::uno::Sequence< DstType > result( i_Container.size() ); + ::std::copy( i_Container.begin(), i_Container.end(), result.getArray() ); + return result; + } + + template <typename T> + inline ::com::sun::star::uno::Sequence<T> containerToSequence( + ::std::vector<T> const& v ) + { + return ::com::sun::star::uno::Sequence<T>( + v.empty() ? 0 : &v[0], static_cast<sal_Int32>(v.size()) ); + } + + //------------------------------------------------------------------------- + /** Copy from a Sequence into a container + + @tpl SrcType + Sequence element type. Must be assignable to SrcType's + elements + + @tpl DstType + Container type. This type must fulfill the STL container and + sequence concepts, in particular, the begin(), end() and the + unary constructor DstType(int) methods must be available and + have the usual semantics. + + @param i_Sequence + Reference to a Sequence of SrcType elements + + @return the generated container + + @attention this function always performs a copy. Furthermore, + when copying from e.g. a Sequence<double> to a vector<int>, no + proper rounding will be performed, but the values will be + truncated. There's currently no measure to prevent or detect + precision loss, overflow or truncation. + */ + template < typename DstType, typename SrcType > + DstType sequenceToContainer( const ::com::sun::star::uno::Sequence< SrcType >& i_Sequence ) + { + DstType result( i_Sequence.getLength() ); + ::std::copy( i_Sequence.getConstArray(), i_Sequence.getConstArray()+i_Sequence.getLength(), result.begin() ); + return result; + } + //------------------------------------------------------------------------- + /** Copy from a Sequence into an existing container + + This potentially saves a needless extra copy operation over + the whole container, as it passes the target object by + reference. + + @tpl SrcType + Sequence element type. Must be assignable to SrcType's + elements + + @tpl DstType + Container type. This type must fulfill the STL container and + sequence concepts, in particular, the begin(), end() and + resize(int) methods must be available and have the usual + semantics. + + @param o_Output + Reference to the target container + + @param i_Sequence + Reference to a Sequence of SrcType elements + + @return a non-const reference to the given container + + @attention this function always performs a copy. Furthermore, + when copying from e.g. a Sequence<double> to a vector<int>, no + proper rounding will be performed, but the values will be + truncated. There's currently no measure to prevent or detect + precision loss, overflow or truncation. + */ + template < typename DstType, typename SrcType > + DstType& sequenceToContainer( DstType& o_Output, const ::com::sun::star::uno::Sequence< SrcType >& i_Sequence ) + { + o_Output.resize( i_Sequence.getLength() ); + ::std::copy( i_Sequence.getConstArray(), i_Sequence.getConstArray()+i_Sequence.getLength(), o_Output.begin() ); + return o_Output; + } + +//......................................................................... +} // namespace comphelper +//......................................................................... + + +#endif // _COMPHELPER_SEQUENCE_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/sequenceashashmap.hxx b/include/comphelper/sequenceashashmap.hxx new file mode 100644 index 000000000000..0c8353776931 --- /dev/null +++ b/include/comphelper/sequenceashashmap.hxx @@ -0,0 +1,313 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX_ +#define _COMPHELPER_SEQUENCEASHASHMAP_HXX_ + +#include <boost/unordered_map.hpp> + +#include <algorithm> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> + +#include <com/sun/star/beans/IllegalTypeException.hpp> +#include "comphelper/comphelperdllapi.h" + + +namespace comphelper{ + + +/** @short Implements a stl hash map on top of some + specialized sequence from type PropertyValue + or NamedValue. + + @descr That provides the possibility to modify + such name sequences very easy ... + */ + +struct SequenceAsHashMapBase : public ::boost::unordered_map< + OUString , + ::com::sun::star::uno::Any , + OUStringHash , + ::std::equal_to< OUString > > +{ +}; + +class COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAsHashMapBase +{ + //------------------------------------------- + public: + + //--------------------------------------- + /** @short creates an empty hash map. + */ + SequenceAsHashMap(); + + //--------------------------------------- + /** @see operator<<(const ::com::sun::star::uno::Any&) + */ + SequenceAsHashMap(const ::com::sun::star::uno::Any& aSource); + + //--------------------------------------- + /** @see operator<<(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&) + */ + SequenceAsHashMap(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lSource); + + //--------------------------------------- + /** @see operator<<(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&) + */ + SequenceAsHashMap(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource); + + //--------------------------------------- + /** @see operator<<(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >&) + */ + SequenceAsHashMap(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& lSource); + + //--------------------------------------- + /** @short not realy used but maybe useful :-) + */ + ~SequenceAsHashMap(); + + //--------------------------------------- + /** @short fill this map from the given + any, which of course must contain + a suitable sequence of element types + "css.beans.PropertyValue" or "css.beans.NamedValue". + + @attention If the given Any is an empty one + (if its set to VOID), no exception + is thrown. In such case this instance will + be created as an empty one too! + + @param aSource + contains the new items for this map. + + @throw An <type scope="com::sun::star::beans">IllegalTypeException</type> + is thrown, if the given any does not contain a suitable sequence ... + but not if its a VOID Any! + */ + void operator<<(const ::com::sun::star::uno::Any& aSource); + + //--------------------------------------- + /** @short fill this map from the given + sequence, where every Any must contain + an item from type "css.beans.PropertyValue" + "css.beans.NamedValue". + + @param lSource + contains the new items for this map. + + @throw An <type scope="com::sun::star::beans">IllegalTypeException</type> + is thrown, if the given any sequence + uses wrong types for its items. VOID Any will be ignored! + */ + void operator<<(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lSource); + + //--------------------------------------- + /** @short fill this map from the given + PropertyValue sequence. + + @param lSource + contains the new items for this map. + */ + void operator<<(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource); + + //--------------------------------------- + /** @short fill this map from the given + NamedValue sequence. + + @param lSource + contains the new items for this map. + */ + void operator<<(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& lSource); + + //--------------------------------------- + /** @short converts this map instance to an + PropertyValue sequence. + + @param lDestination + target sequence for converting. + */ + void operator>>(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lDestination) const; + + //--------------------------------------- + /** @short converts this map instance to an + NamedValue sequence. + + @param lDestination + target sequence for converting. + */ + void operator>>(::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& lDestination) const; + + //--------------------------------------- + /** @short return this map instance as an + Any, which can be + used in const environments only. + + @descr Its made const to prevent using of the + return value directly as an in/out parameter! + usage: myMethod(stlDequeAdapter.getAsAnyList()); + + @param bAsPropertyValue + switch between using of PropertyValue or NamedValue as + value type. + + @return A const Any, which + contains all items of this map. + */ + const ::com::sun::star::uno::Any getAsConstAny(::sal_Bool bAsPropertyValue) const; + + //--------------------------------------- + /** @short return this map instance to as a + NamedValue sequence, which can be + used in const environments only. + + @descr Its made const to prevent using of the + return value directly as an in/out parameter! + usage: myMethod(stlDequeAdapter.getAsNamedValueList()); + + @return A const sequence of type NamedValue, which + contains all items of this map. + */ + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > getAsConstNamedValueList() const; + + //--------------------------------------- + /** @short return this map instance to as a + PropertyValue sequence, which can be + used in const environments only. + + @descr Its made const to prevent using of the + return value directly as an in/out parameter! + usage: myMethod(stlDequeAdapter.getAsPropertyValueList()); + + @return A const sequence of type PropertyValue, which + contains all items of this map. + */ + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > getAsConstPropertyValueList() const; + + //--------------------------------------- + /** @short check if the specified item exists + and return its (unpacked!) value or it returns the + specified default value otherwise. + + @descr If a value should be extracted only in case + the requsted property exists realy (without creating + of new items as it the index operator of a + has_map does!) this method can be used. + + @param sKey + key name of the item. + + @param aDefault + the default value, which is returned + if the specified item could not + be found. + + @return The (unpacked!) value of the specified property or + the given default value otherwise. + + @attention "unpacked" means the Any content of every iterator->second! + */ + template< class TValueType > + TValueType getUnpackedValueOrDefault(const OUString& sKey , + const TValueType& aDefault) const + { + const_iterator pIt = find(sKey); + if (pIt == end()) + return aDefault; + + TValueType aValue = TValueType(); + if (!(pIt->second >>= aValue)) + return aDefault; + + return aValue; + } + + //--------------------------------------- + /** @short creates a new item with the specified + name and value only in case such item name + does not already exist. + + @descr To check if the property already exists only + her name is used for compare. Its value isnt + checked! + + @param sKey + key name of the property. + + @param aValue + the new (unpacked!) value. + Note: This value will be transformed to an Any + internaly, because only Any values can be + part of a PropertyValue or NamedValue structure. + + @return TRUE if this property was added as new item; + FALSE if it already exists. + */ + template< class TValueType > + sal_Bool createItemIfMissing(const OUString& sKey , + const TValueType& aValue) + { + if (find(sKey) == end()) + { + (*this)[sKey] = ::com::sun::star::uno::makeAny(aValue); + return sal_True; + } + + return sal_False; + } + + //--------------------------------------- + /** @short check if all items of given map + exists in these called map also. + + @descr Every item of the given map must exists + with same name and value inside these map. + But these map can contain additional items + which are not part of the search-map. + + @param rCheck + the map containing all items for checking. + + @return + TRUE if all items of Rcheck could be found + in these map; FALSE otherwise. + */ + sal_Bool match(const SequenceAsHashMap& rCheck) const; + + //--------------------------------------- + /** @short merge all values from the given map into + this one. + + @descr Existing items will be overwritten ... + missing items will be created new ... + but non specified items will stay alive ! + + @param rSource + the map containing all items for the update. + */ + void update(const SequenceAsHashMap& rSource); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_SEQUENCEASHASHMAP_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/sequenceasvector.hxx b/include/comphelper/sequenceasvector.hxx new file mode 100644 index 000000000000..305eba9245ff --- /dev/null +++ b/include/comphelper/sequenceasvector.hxx @@ -0,0 +1,247 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_SEQUENCEASVECTOR_HXX_ +#define _COMPHELPER_SEQUENCEASVECTOR_HXX_ + +#include <vector> +#include <algorithm> +#include <com/sun/star/uno/Sequence.hxx> + +#include <com/sun/star/beans/IllegalTypeException.hpp> + + +namespace comphelper{ + + +/** @short Implements a stl vector on top of any + uno sequence. + + @descr That provides the possibility to modify + sequences very easy ... + Of course this can be useful only, if + count of modifications is high, so copying + of the sequence make sense! + */ +template< class TElementType > +class SequenceAsVector : public ::std::vector< TElementType > +{ + //------------------------------------------- + // types + + public: + + //--------------------------------------- + /** @short When inheriting from a template using typename is generally required when using + types from the base! */ + typedef typename ::std::vector< TElementType >::const_iterator const_iterator; + + //--------------------------------------- + /** @short When inheriting from a template using typename is generally required when using + types from the base! */ + typedef typename ::std::vector< TElementType >::iterator iterator; + + //------------------------------------------- + // interface + public: + + //--------------------------------------- + /** @short default ctor, to create an empty list. + */ + SequenceAsVector() + {} + + //--------------------------------------- + /** @short default dtor + */ + ~SequenceAsVector() + {} + + //--------------------------------------- + /** @short creates a new vector with the given length. + + @param nLength + the number of elements for the new vector. + */ + explicit SequenceAsVector(sal_Int32 nLength) : + ::std::vector< TElementType >( static_cast< size_t >( nLength ) ) + { + } + + //--------------------------------------- + /** @short creates a new deque from the given uno sequence. + + @param lSource + contains the new items for this deque. + */ + SequenceAsVector(const ::com::sun::star::uno::Sequence< TElementType >& lSource) + { + (*this) << lSource; + } + + //--------------------------------------- + /** @short creates a new instance from the given Any, which + of course must contain a valid sequence using the + right element type for every item. + + @attention If the given Any is an empty one + (if its set to VOID), no exception + is thrown. In such case this instance will + be created as an empty one too! + + @param aSource + this any must contain a suitable sequence. :-) + + @throw A <type scope="com::sun::star::beans">IllegalTypeException</type> + if an unsupported element inside this Any + is given. An empty Any reset this instance! + */ + SequenceAsVector(const ::com::sun::star::uno::Any& aSource) + { + (*this) << aSource; + } + + //--------------------------------------- + /** @short fill this instance from the given uno sequence. + + @param lSource + contains the new items for this deque. + */ + void operator<<(const ::com::sun::star::uno::Sequence< TElementType >& lSource) + { + this->clear(); + + sal_Int32 c = lSource.getLength(); + const TElementType* pSource = lSource.getConstArray(); + + for (sal_Int32 i=0; i<c; ++i) + this->push_back(pSource[i]); + } + + //--------------------------------------- + /** @short fill this instance from the given Any, which + of course must contain a valid sequence using the + right element type for every item. + + @attention If the given Any is an empty one + (if its set to VOID), no exception + is thrown. In such case this instance will + be created as an empty one too! + + @param aSource + this any must contain a suitable sequence. :-) + + @throw A <type scope="com::sun::star::beans">IllegalTypeException</type> + if an unsupported element inside this Any + is given. An empty Any reset this instance! + */ + void operator<<(const ::com::sun::star::uno::Any& aSource) + { + // An empty Any reset this instance! + if (!aSource.hasValue()) + { + this->clear(); + return; + } + + ::com::sun::star::uno::Sequence< TElementType > lSource; + if (!(aSource >>= lSource)) + throw ::com::sun::star::beans::IllegalTypeException( + OUString("SequenceAsVector operator<<(Any) was called with an unsupported Any type."), + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()); + + (*this) << lSource; + } + + //--------------------------------------- + /** @short converts this instance to an uno sequence. + + @param lDestination + target sequence for converting. + */ + void operator>>(::com::sun::star::uno::Sequence< TElementType >& lDestination) const + { + sal_Int32 c = (sal_Int32)this->size(); + lDestination.realloc(c); + TElementType* pDestination = lDestination.getArray(); + + sal_Int32 i = 0; + for (typename std::vector<TElementType>::const_iterator pThis = this->begin(); + pThis != this->end() ; + ++pThis ) + { + pDestination[i] = *pThis; + ++i; + } + } + + //--------------------------------------- + /** @short converts this instance to an uno any + which contains a suitable sequence + of items of this stl struct. + + @param aDestination + target any for converting. + */ + void operator>>(::com::sun::star::uno::Any& aDestination) const + { + sal_Int32 c = (sal_Int32)this->size(); + ::com::sun::star::uno::Sequence< TElementType > lDestination(c); + TElementType* pDestination = lDestination.getArray(); + + sal_Int32 i = 0; + for (typename std::vector<TElementType>::const_iterator pThis = this->begin(); + pThis != this->end() ; + ++pThis ) + { + pDestination[i] = *pThis; + ++i; + } + + aDestination <<= lDestination; + } + + //--------------------------------------- + /** @short converts this deque to a suitable uno + sequence which contains all items. + + @attention It return a const sequence to prevent + the outside code against using of this + return value as [in/]out parameter for + direct function calls! + Of course it can be casted to non const + ... but then its a problem of the outside + code :-) + + @return A (const!) sequence, which contains all items of + this deque. + */ + const ::com::sun::star::uno::Sequence< TElementType > getAsConstList() const + { + ::com::sun::star::uno::Sequence< TElementType > lDestination; + (*this) >> lDestination; + return lDestination; + } +}; + +} // namespace comphelper + +#endif // _COMPHELPER_SEQUENCEASVECTOR_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/servicedecl.hxx b/include/comphelper/servicedecl.hxx new file mode 100644 index 000000000000..be3b275cf215 --- /dev/null +++ b/include/comphelper/servicedecl.hxx @@ -0,0 +1,409 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef COMPHELPER_SERVICEDECL_HXX_INCLUDED +#define COMPHELPER_SERVICEDECL_HXX_INCLUDED + +#include <comphelper/comphelperdllapi.h> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <uno/environment.h> +#include <boost/utility.hpp> +#include <boost/function.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/repetition.hpp> +#include <boost/preprocessor/seq/enum.hpp> + +namespace comphelper { +namespace service_decl { + +class ServiceDecl; + +namespace detail { +typedef ::boost::function3< + css::uno::Reference<css::uno::XInterface> /* return */, + ServiceDecl const&, + css::uno::Sequence<css::uno::Any> const&, + css::uno::Reference<css::uno::XComponentContext> const&> CreateFuncF; +} + +/** Class to declare a service implementation. There is no need to implement + lang::XServiceInfo nor lang::XInitialization anymore. + The declaration can be done in various ways, the (simplest) form is + + <pre> + class MyClass : public cppu::WeakImplHelper2<XInterface1, XInterface2> { + public: + MyClass( uno::Reference<uno::XComponentContext> const& xContext ) + [...] + }; + [...] + namespace sdecl = comphelper::service_decl; + sdecl::ServiceDecl const myDecl( + sdecl::class_<MyClass>(), + "my.unique.implementation.name", + "MyServiceSpec1;MyServiceSpec2" ); + </pre> + + If the service demands initialization by arguments, the implementation + class has to define a constructor taking both arguments and component + context: + + <pre> + class MyClass : public cppu::WeakImplHelper2<XInterface1, XInterface2> { + public: + MyClass( uno::Sequence<uno::Any> const& args, + uno::Reference<uno:XComponentContext> const& xContext ) + [...] + }; + [...] + namespace sdecl = comphelper::service_decl; + sdecl::ServiceDecl const myDecl( + sdecl::class_<MyClass, sdecl::with_args<true> >(), + "my.unique.implementation.name", + "MyServiceSpec1;MyServiceSpec2" ); + </pre> + + Additionally, there is the possibility to process some code after creation, + e.g. to add the newly created object as a listener or perform aggregation + (C++-UNO only): + + <pre> + uno::Reference<uno::XInterface> somePostProcCode( MyClass * p ); + [...] + namespace sdecl = comphelper::service_decl; + sdecl::ServiceDecl const myDecl( + sdecl::class_<MyClass, ... >(&somePostProcCode), + "my.unique.implementation.name", + "MyServiceSpec1;MyServiceSpec2" ); + </pre> + + In the latter case, somePostProcCode gets the yet unacquired "raw" pointer. +*/ +class COMPHELPER_DLLPUBLIC ServiceDecl : private ::boost::noncopyable +{ +public: + /** Ctor for multiple supported service names. + + @param implClass implementation class description + @param pImplName implementation name + @param pSupportedServiceNames supported service names + @param cDelim delimiter for supported service names + */ + template <typename ImplClassT> + ServiceDecl( ImplClassT const& implClass, + char const* pImplName, + char const* pSupportedServiceNames, char cDelim = ';' ) + : m_createFunc(implClass.m_createFunc), + m_pImplName(pImplName), + m_pServiceNames(pSupportedServiceNames), + m_cDelim(cDelim) {} + + /// @internal gets called by component_getFactoryHelper() + void * getFactory( sal_Char const* pImplName ) const; + + /// @return supported service names + ::com::sun::star::uno::Sequence< OUString> + getSupportedServiceNames() const; + + /// @return whether name is in set of supported service names + bool supportsService( OUString const& name ) const; + + /// @return implementation name + OUString getImplementationName() const; + +private: + class Factory; + friend class Factory; + + detail::CreateFuncF const m_createFunc; + char const* const m_pImplName; + char const* const m_pServiceNames; + char const m_cDelim; +}; + +/** To specify whether the implementation class expects arguments + (uno::Sequence<uno::Any>). +*/ +template <bool> struct with_args; + +/// @internal +namespace detail { +template <typename ImplT> +class OwnServiceImpl + : public ImplT, + private ::boost::noncopyable +{ + typedef ImplT BaseT; + +public: + OwnServiceImpl( + ServiceDecl const& rServiceDecl, + css::uno::Sequence<css::uno::Any> const& args, + css::uno::Reference<css::uno::XComponentContext> const& xContext ) + :BaseT(args, xContext), m_rServiceDecl(rServiceDecl) {} + OwnServiceImpl( + ServiceDecl const& rServiceDecl, + css::uno::Reference<css::uno::XComponentContext> const& xContext ) + : BaseT(xContext), m_rServiceDecl(rServiceDecl) {} + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException) { + return m_rServiceDecl.getImplementationName(); + } + virtual sal_Bool SAL_CALL supportsService( OUString const& name ) + throw (css::uno::RuntimeException) { + return m_rServiceDecl.supportsService(name); + } + virtual css::uno::Sequence< OUString> + SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException) { + return m_rServiceDecl.getSupportedServiceNames(); + } + +private: + ServiceDecl const& m_rServiceDecl; +}; + +template <typename ImplT> +class ServiceImpl : public OwnServiceImpl< ::cppu::ImplInheritanceHelper1<ImplT,css::lang::XServiceInfo> > +{ +typedef OwnServiceImpl< ::cppu::ImplInheritanceHelper1<ImplT,css::lang::XServiceInfo> > ServiceImpl_BASE; +public: + ServiceImpl( + ServiceDecl const& rServiceDecl, + css::uno::Sequence<css::uno::Any> const& args, + css::uno::Reference<css::uno::XComponentContext> const& xContext ) + : ServiceImpl_BASE(rServiceDecl, args, xContext) {} + ServiceImpl( + ServiceDecl const& rServiceDecl, + css::uno::Reference<css::uno::XComponentContext> const& xContext ) + : ServiceImpl_BASE(rServiceDecl, xContext) {} +}; + +template <typename ServiceImplT> +struct PostProcessDefault { + css::uno::Reference<css::uno::XInterface> + operator()( ServiceImplT * p ) const { + return static_cast<css::lang::XServiceInfo *>(p); + } +}; + +template <typename ImplT, typename PostProcessFuncT, typename WithArgsT> +struct CreateFunc; + +template <typename ImplT, typename PostProcessFuncT> +struct CreateFunc<ImplT, PostProcessFuncT, with_args<false> > { + PostProcessFuncT const m_postProcessFunc; + explicit CreateFunc( PostProcessFuncT const& postProcessFunc ) + : m_postProcessFunc(postProcessFunc) {} + + css::uno::Reference<css::uno::XInterface> + operator()( ServiceDecl const& rServiceDecl, + css::uno::Sequence<css::uno::Any> const&, + css::uno::Reference<css::uno::XComponentContext> + const& xContext ) const + { + return m_postProcessFunc( + new ImplT( rServiceDecl, xContext ) ); + } +}; + +template <typename ImplT, typename PostProcessFuncT> +struct CreateFunc<ImplT, PostProcessFuncT, with_args<true> > { + PostProcessFuncT const m_postProcessFunc; + explicit CreateFunc( PostProcessFuncT const& postProcessFunc ) + : m_postProcessFunc(postProcessFunc) {} + + css::uno::Reference<css::uno::XInterface> + operator()( ServiceDecl const& rServiceDecl, + css::uno::Sequence<css::uno::Any> const& args, + css::uno::Reference<css::uno::XComponentContext> + const& xContext ) const + { + return m_postProcessFunc( + new ImplT( rServiceDecl, args, xContext ) ); + } +}; + +} // namespace detail + +/** Defines a service implementation class. + + @tpl ImplT_ service implementation class + @WithArgsT whether the implementation class ctor expects arguments + (uno::Sequence<uno::Any>, uno::Reference<uno::XComponentContext>) + or just (uno::Reference<uno::XComponentContext>) +*/ +template <typename ImplT_, typename WithArgsT = with_args<false> > +struct serviceimpl_base { + typedef ImplT_ ImplT; + + detail::CreateFuncF const m_createFunc; + + typedef detail::PostProcessDefault<ImplT> PostProcessDefaultT; + + /** Default ctor. Implementation class without args, expecting + component context as single argument. + */ + serviceimpl_base() : m_createFunc( + detail::CreateFunc<ImplT, PostProcessDefaultT, WithArgsT>( + PostProcessDefaultT() ) ) {} + + /** Ctor to pass a post processing function/functor. + + @tpl PostProcessDefaultT let your compiler deduce this + @param postProcessFunc function/functor that gets the yet unacquired + ImplT_ pointer returning a + uno::Reference<uno::XInterface> + */ + template <typename PostProcessFuncT> + explicit serviceimpl_base( PostProcessFuncT const& postProcessFunc ) + : m_createFunc( detail::CreateFunc<ImplT, PostProcessFuncT, WithArgsT>( + postProcessFunc ) ) {} +}; + +template <typename ImplT_, typename WithArgsT = with_args<false> > +struct class_ : public serviceimpl_base< detail::ServiceImpl<ImplT_>, WithArgsT > +{ + typedef serviceimpl_base< detail::ServiceImpl<ImplT_>, WithArgsT > baseT; + /** Default ctor. Implementation class without args, expecting + component context as single argument. + */ + class_() : baseT() {} + template <typename PostProcessFuncT> + /** Ctor to pass a post processing function/functor. + + @tpl PostProcessDefaultT let your compiler deduce this + @param postProcessFunc function/functor that gets the yet unacquired + ImplT_ pointer returning a + uno::Reference<uno::XInterface> + */ + explicit class_( PostProcessFuncT const& postProcessFunc ) : baseT( postProcessFunc ) {} +}; + +// +// component_... helpers with arbitrary service declarations: +// + +#define COMPHELPER_SERVICEDECL_getFactory(z_, n_, unused_) \ + if (pRet == 0) \ + pRet = BOOST_PP_CAT(s, n_).getFactory(pImplName); + +/** The following preprocessor repetitions generate functions like + + <pre> + inline void * component_getFactoryHelper( + sal_Char const* pImplName, + ::com::sun::star::lang::XMultiServiceFactory *, + ::com::sun::star::registry::XRegistryKey * xRegistryKey, + ServiceDecl const& s0, ServiceDecl const& s1, ... ); + </pre> + + which call on the passed service declarations. + + The maximum number of service declarations can be set by defining + COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS; its default is 8. +*/ +#define COMPHELPER_SERVICEDECL_make(z_, n_, unused_) \ +inline void * component_getFactoryHelper( \ + sal_Char const* pImplName, \ + ::com::sun::star::lang::XMultiServiceFactory *, \ + ::com::sun::star::registry::XRegistryKey *, \ + BOOST_PP_ENUM_PARAMS(n_, ServiceDecl const& s) ) \ +{ \ + void * pRet = 0; \ + BOOST_PP_REPEAT(n_, COMPHELPER_SERVICEDECL_getFactory, ~) \ + return pRet; \ +} + +#ifndef COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS +#define COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS 8 +#endif + +BOOST_PP_REPEAT_FROM_TO(1, COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS, + COMPHELPER_SERVICEDECL_make, ~) + +#undef COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS +#undef COMPHELPER_SERVICEDECL_make +#undef COMPHELPER_SERVICEDECL_getFactory + +} // namespace service_decl +} // namespace comphelper + +/** The following preprocessor macro generates the C access functions, + that are used to initialize and register the components of a + shared library object. + + If you have, say, written a lib that contains three distinct + components, each with its own ServiceDecl object, you might want + to employ the following code: + + <pre> + // must reside outside _any_ namespace + COMPHELPER_SERVICEDECL_EXPORTS3(yourServiceDecl1, + yourServiceDecl2, + yourServiceDecl3); + </pre> + + For your convenience, the COMPHELPER_SERVICEDECL_EXPORTS<N> macro + comes pre-defined up to N=8, if you should need more arguments, + call COMPHELPER_SERVICEDECL_make_exports directly, like this: + + <pre> + // must reside outside _any_ namespace + COMPHELPER_SERVICEDECL_make_exports((yourServiceDecl1)(yourServiceDecl2)...(yourServiceDeclN)); + </pre> + + Note the missing colons between the bracketed arguments. + */ +#define COMPHELPER_SERVICEDECL_make_exports(compName, varargs_ ) \ +extern "C" \ +{ \ + SAL_DLLPUBLIC_EXPORT void* SAL_CALL compName##_component_getFactory( sal_Char const* pImplName, \ + ::com::sun::star::lang::XMultiServiceFactory* pServiceManager, \ + ::com::sun::star::registry::XRegistryKey* pRegistryKey ) \ + { \ + return component_getFactoryHelper( pImplName, pServiceManager, \ + pRegistryKey, \ + BOOST_PP_SEQ_ENUM(varargs_) ); \ + } \ +} + +#define COMPHELPER_SERVICEDECL_EXPORTS1(compName,comp0_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)) +#define COMPHELPER_SERVICEDECL_EXPORTS2(compName,comp0_,comp1_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)) +#define COMPHELPER_SERVICEDECL_EXPORTS3(compName,comp0_,comp1_,comp2_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)(comp2_)) +#define COMPHELPER_SERVICEDECL_EXPORTS4(compName,comp0_,comp1_,comp2_,comp3_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)(comp2_)(comp3_)) +#define COMPHELPER_SERVICEDECL_EXPORTS5(compName,comp0_,comp1_,comp2_,comp3_,comp4_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)(comp2_)(comp3_)(comp4_)) +#define COMPHELPER_SERVICEDECL_EXPORTS6(compName,comp0_,comp1_,comp2_,comp3_,comp4_,comp5_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)(comp2_)(comp3_)(comp4_)(comp5_)) +#define COMPHELPER_SERVICEDECL_EXPORTS7(compName,comp0_,comp1_,comp2_,comp3_,comp4_,comp5_,comp6_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)(comp2_)(comp3_)(comp4_)(comp5_)(comp6_)) +#define COMPHELPER_SERVICEDECL_EXPORTS8(compName,comp0_,comp1_,comp2_,comp3_,comp4_,comp5_,comp6_,comp7_) \ + COMPHELPER_SERVICEDECL_make_exports(compName,(comp0_)(comp1_)(comp2_)(comp3_)(comp4_)(comp5_)(comp6_)(comp7_)) + +#endif // ! defined(COMPHELPER_SERVICEDECL_HXX_INCLUDED) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/servicehelper.hxx b/include/comphelper/servicehelper.hxx new file mode 100644 index 000000000000..a861e88db2d7 --- /dev/null +++ b/include/comphelper/servicehelper.hxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_SERVICEHELPER_HXX_ +#define _COMPHELPER_SERVICEHELPER_HXX_ + +#include <rtl/uuid.h> +#include <rtl/instance.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +class UnoTunnelIdInit +{ +private: + ::com::sun::star::uno::Sequence< sal_Int8 > m_aSeq; +public: + UnoTunnelIdInit() : m_aSeq(16) + { + rtl_createUuid( (sal_uInt8*)m_aSeq.getArray(), 0, sal_True ); + } + const ::com::sun::star::uno::Sequence< sal_Int8 >& getSeq() const { return m_aSeq; } +}; + +/** the UNO3_GETIMPLEMENTATION_* macros implement a static helper function + that gives access to your implementation for a given interface reference, + if possible. + + Example: + MyClass* pClass = MyClass::getImplementation( xRef ); + + Usage: + Put a UNO3_GETIMPLEMENTATION_DECL( classname ) inside your class + definitian and UNO3_GETIMPLEMENTATION_IMPL( classname ) inside + your cxx file. Your class must inherit ::com::sun::star::uno::XUnoTunnel + and export it with queryInterface. Implementation of XUnoTunnel is + done by this macro. +*/ +#define UNO3_GETIMPLEMENTATION_DECL( classname ) \ + static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw(); \ + static classname* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInt ); \ + virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); + +#define UNO3_GETIMPLEMENTATION_BASE_IMPL( classname ) \ +namespace \ +{ \ + class the##classname##UnoTunnelId : public rtl::Static< UnoTunnelIdInit, the##classname##UnoTunnelId> {}; \ +} \ +const ::com::sun::star::uno::Sequence< sal_Int8 > & classname::getUnoTunnelId() throw() \ +{ \ + return the##classname##UnoTunnelId::get().getSeq(); \ +} \ +\ +classname* classname::getImplementation( const uno::Reference< uno::XInterface >& xInt ) \ +{ \ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xInt, ::com::sun::star::uno::UNO_QUERY ); \ + if( xUT.is() ) \ + return reinterpret_cast<classname*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( classname::getUnoTunnelId() ))); \ + else \ + return NULL; \ +} + +#define UNO3_GETIMPLEMENTATION_IMPL( classname )\ +UNO3_GETIMPLEMENTATION_BASE_IMPL(classname)\ +sal_Int64 SAL_CALL classname::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException) \ +{ \ + if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(), \ + rId.getConstArray(), 16 ) ) \ + { \ + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); \ + } \ + return 0; \ +} + +#define UNO3_GETIMPLEMENTATION2_IMPL( classname, baseclass )\ +UNO3_GETIMPLEMENTATION_BASE_IMPL(classname)\ +sal_Int64 SAL_CALL classname::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException) \ +{ \ + if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(), \ + rId.getConstArray(), 16 ) ) \ + { \ + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); \ + } \ + else \ + { \ + return baseclass::getSomething( rId ); \ + } \ +} + + +#endif // _COMPHELPER_SERVICEHELPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/serviceinfohelper.hxx b/include/comphelper/serviceinfohelper.hxx new file mode 100644 index 000000000000..25169d1043a0 --- /dev/null +++ b/include/comphelper/serviceinfohelper.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_SERVICEINFOHELPER_HXX +#define COMPHELPER_SERVICEINFOHELPER_HXX + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper { + +/** this class provides a basic helper for classes suporting the XServiceInfo Interface. + * + * you can overload the <code>getSupprotedServiceNames</code> to implement a XServiceInfo. + * you can use the static helper methods to combine your services with that of parent + * or aggregatet classes. + */ +class COMPHELPER_DLLPUBLIC ServiceInfoHelper : public ::com::sun::star::lang::XServiceInfo +{ +public: + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // helper + static void addToSequence( ::com::sun::star::uno::Sequence< OUString >& rSeq, sal_uInt16 nServices, /* sal_Char* */... ) throw(); + static sal_Bool SAL_CALL supportsService( const OUString& ServiceName, const ::com::sun::star::uno::Sequence< OUString >& SupportedServices ) throw(); + +protected: + ~ServiceInfoHelper() {} +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/sharedmutex.hxx b/include/comphelper/sharedmutex.hxx new file mode 100644 index 000000000000..8013e7f404aa --- /dev/null +++ b/include/comphelper/sharedmutex.hxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_SHAREDMUTEX_HXX +#define COMPHELPER_SHAREDMUTEX_HXX + +#include "comphelper/comphelperdllapi.h" + +#include <osl/mutex.hxx> + +#include <boost/shared_ptr.hpp> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //============================================================ + //= SharedMutex + //============================================================ + class COMPHELPER_DLLPUBLIC SharedMutex + { + public: + SharedMutex(); + SharedMutex( const SharedMutex& ); + SharedMutex& operator=( const SharedMutex& ); + ~SharedMutex() + { + } + + inline ::osl::Mutex& getMutex() { return *m_pMutexImpl; } + inline operator ::osl::Mutex& () { return *m_pMutexImpl; } + + private: + ::boost::shared_ptr< ::osl::Mutex > m_pMutexImpl; + }; + + //============================================================ + //= SharedMutexBase + //============================================================ + /** sometimes, it's necessary to have an initialized ::osl::Mutex to pass + to some ctor call of your base class. In this case, you can't hold the + SharedMutex as member, but you need to move it into another base class, + which is initialized before the mutex-requiring class is. + */ + class COMPHELPER_DLLPUBLIC SharedMutexBase + { + protected: + SharedMutexBase() + { + } + ~SharedMutexBase() + { + } + + protected: + ::osl::Mutex& getMutex() const { return m_aMutex; } + SharedMutex& getSharedMutex() const { return m_aMutex; } + + private: + mutable SharedMutex m_aMutex; + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_SHAREDMUTEX_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/stillreadwriteinteraction.hxx b/include/comphelper/stillreadwriteinteraction.hxx new file mode 100644 index 000000000000..c6d62e8da9e2 --- /dev/null +++ b/include/comphelper/stillreadwriteinteraction.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_STILLREADWRITEINTERACTION_HXX_ +#define _COMPHELPER_STRILLREADWRITEINTERACTION_HXX_ + +#include <ucbhelper/interceptedinteraction.hxx> + +#include <com/sun/star/task/XInteractionHandler.hpp> + +#include "comphelper/comphelperdllapi.h" + + +namespace comphelper{ +class COMPHELPER_DLLPUBLIC StillReadWriteInteraction : public ::ucbhelper::InterceptedInteraction +{ +private: + static const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0; + static const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1; + + sal_Bool m_bUsed; + sal_Bool m_bHandledByMySelf; + sal_Bool m_bHandledByInternalHandler; + +public: + StillReadWriteInteraction(const com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >& xHandler); + + void resetInterceptions(); + void resetErrorStates(); + sal_Bool wasWriteError(); + +private: + virtual ucbhelper::InterceptedInteraction::EInterceptionState intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest, + const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest); + +}; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/stl_types.hxx b/include/comphelper/stl_types.hxx new file mode 100644 index 000000000000..cef5afdff3f2 --- /dev/null +++ b/include/comphelper/stl_types.hxx @@ -0,0 +1,273 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_STLTYPES_HXX_ +#define _COMPHELPER_STLTYPES_HXX_ + +#include "sal/config.h" + +#include <vector> +#include <map> + +#include <stack> +#include <set> + +#include <math.h> // prevent conflict between exception and std::exception +#include <functional> + + +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> + +//... namespace comphelper ................................................ +namespace comphelper +{ +//......................................................................... + +//======================================================================== +// comparisation functions + +//------------------------------------------------------------------------ + struct UStringLess : public ::std::binary_function< OUString, OUString, bool> +{ + bool operator() (const OUString& x, const OUString& y) const { return x < y ? true : false;} // construct prevents a MSVC6 warning +}; +//------------------------------------------------------------------------ +struct UStringMixLess : public ::std::binary_function< OUString, OUString, bool> +{ + bool m_bCaseSensitive; +public: + UStringMixLess(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){} + bool operator() (const OUString& x, const OUString& y) const + { + if (m_bCaseSensitive) + return rtl_ustr_compare(x.getStr(), y.getStr()) < 0 ? true : false; + else + return rtl_ustr_compareIgnoreAsciiCase(x.getStr(), y.getStr()) < 0 ? true : false; + } + + bool isCaseSensitive() const {return m_bCaseSensitive;} +}; +//------------------------------------------------------------------------ +struct UStringEqual +{ + sal_Bool operator() (const OUString& lhs, const OUString& rhs) const { return lhs.equals( rhs );} +}; + +//------------------------------------------------------------------------ +struct UStringIEqual +{ + sal_Bool operator() (const OUString& lhs, const OUString& rhs) const { return lhs.equalsIgnoreAsciiCase( rhs );} +}; + +//------------------------------------------------------------------------ +class UStringMixEqual +{ + sal_Bool m_bCaseSensitive; + +public: + UStringMixEqual(sal_Bool bCaseSensitive = sal_True):m_bCaseSensitive(bCaseSensitive){} + sal_Bool operator() (const OUString& lhs, const OUString& rhs) const + { + return m_bCaseSensitive ? lhs.equals( rhs ) : lhs.equalsIgnoreAsciiCase( rhs ); + } + sal_Bool isCaseSensitive() const {return m_bCaseSensitive;} +}; +//------------------------------------------------------------------------ +class TStringMixEqualFunctor : public ::std::binary_function< OUString,OUString,bool> +{ + sal_Bool m_bCaseSensitive; + +public: + TStringMixEqualFunctor(sal_Bool bCaseSensitive = sal_True) + :m_bCaseSensitive(bCaseSensitive) + {} + bool operator() (const OUString& lhs, const OUString& rhs) const + { + return !!(m_bCaseSensitive ? lhs.equals( rhs ) : lhs.equalsIgnoreAsciiCase( rhs )); + } + sal_Bool isCaseSensitive() const {return m_bCaseSensitive;} +}; +//------------------------------------------------------------------------ +class TPropertyValueEqualFunctor : public ::std::binary_function< ::com::sun::star::beans::PropertyValue,OUString,bool> +{ +public: + TPropertyValueEqualFunctor() + {} + bool operator() (const ::com::sun::star::beans::PropertyValue& lhs, const OUString& rhs) const + { + return !!(lhs.Name == rhs); + } +}; +//------------------------------------------------------------------------ +class TNamedValueEqualFunctor : public ::std::binary_function< ::com::sun::star::beans::NamedValue,OUString,bool> +{ +public: + TNamedValueEqualFunctor() + {} + bool operator() (const ::com::sun::star::beans::NamedValue& lhs, const OUString& rhs) const + { + return !!(lhs.Name == rhs); + } +}; +//------------------------------------------------------------------------ +class UStringMixHash +{ + sal_Bool m_bCaseSensitive; + +public: + UStringMixHash(sal_Bool bCaseSensitive = sal_True):m_bCaseSensitive(bCaseSensitive){} + size_t operator() (const OUString& rStr) const + { + return m_bCaseSensitive ? rStr.hashCode() : rStr.toAsciiUpperCase().hashCode(); + } + sal_Bool isCaseSensitive() const {return m_bCaseSensitive;} +}; + +//===================================================================== +//= OInterfaceCompare +//===================================================================== +/** is stl-compliant structure for comparing Reference< <iface> > instances +*/ +template < class IAFCE > +struct OInterfaceCompare + :public ::std::binary_function < ::com::sun::star::uno::Reference< IAFCE > + , ::com::sun::star::uno::Reference< IAFCE > + , bool + > +{ + bool operator() (const ::com::sun::star::uno::Reference< IAFCE >& lhs, const ::com::sun::star::uno::Reference< IAFCE >& rhs) const + { + return lhs.get() < rhs.get(); + // this does not make any sense if you see the semantics of the pointer returned by get: + // It's a pointer to a point in memory where an interface implementation lies. + // But for our purpose (provide a reliable less-operator which can be used with the STL), this is + // sufficient .... + } +}; + +template <class _Tp, class _Arg> +class mem_fun1_t : public ::std::binary_function<_Tp*,_Arg,void> +{ + typedef void (_Tp::*_fun_type)(_Arg); +public: + explicit mem_fun1_t(_fun_type __pf) : _M_f(__pf) {} + void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } +private: + _fun_type _M_f; +}; + +template <class _Tp, class _Arg> +inline mem_fun1_t<_Tp,_Arg> mem_fun(void (_Tp::*__f)(_Arg)) +{ + return mem_fun1_t<_Tp,_Arg>(__f); +} + +//......................................................................... +/** output iterator that appends OUStrings into an OUStringBuffer. + */ +class OUStringBufferAppender : + public ::std::iterator< ::std::output_iterator_tag, void, void, void, void> +{ +public: + typedef OUStringBufferAppender Self; + typedef ::std::output_iterator_tag iterator_category; + typedef void value_type; + typedef void reference; + typedef void pointer; + typedef size_t difference_type; + + OUStringBufferAppender(OUStringBuffer & i_rBuffer) + : m_rBuffer(i_rBuffer) { } + Self & operator=(OUString const & i_rStr) + { + m_rBuffer.append( i_rStr ); + return *this; + } + Self & operator*() { return *this; } // so operator= works + Self & operator++() { return *this; } + Self & operator++(int) { return *this; } + +private: + OUStringBuffer & m_rBuffer; +}; + +//......................................................................... +/** algorithm similar to std::copy, but inserts a separator between elements. + */ +template< typename ForwardIter, typename OutputIter, typename T > +OutputIter intersperse( + ForwardIter start, ForwardIter end, OutputIter out, T const & separator) +{ + if (start != end) { + *out = *start; + ++start; + ++out; + } + + while (start != end) { + *out = separator; + ++out; + *out = *start; + ++start; + ++out; + } + + return out; +} + +//......................................................................... +} +//... namespace comphelper ................................................ + +//================================================================== +// consistently defining stl-types +//================================================================== + +#define DECLARE_STL_ITERATORS(classname) \ + typedef classname::iterator classname##Iterator; \ + typedef classname::const_iterator Const##classname##Iterator \ + +#define DECLARE_STL_MAP(keytype, valuetype, comparefct, classname) \ + typedef std::map< keytype, valuetype, comparefct > classname; \ + DECLARE_STL_ITERATORS(classname) \ + +#define DECLARE_STL_STDKEY_MAP(keytype, valuetype, classname) \ + DECLARE_STL_MAP(keytype, valuetype, std::less< keytype >, classname) \ + +#define DECLARE_STL_VECTOR(valuetyp, classname) \ + typedef std::vector< valuetyp > classname; \ + DECLARE_STL_ITERATORS(classname) \ + +#define DECLARE_STL_USTRINGACCESS_MAP(valuetype, classname) \ + DECLARE_STL_MAP(OUString, valuetype, ::comphelper::UStringLess, classname) \ + +#define DECLARE_STL_STDKEY_SET(valuetype, classname) \ + typedef ::std::set< valuetype > classname; \ + DECLARE_STL_ITERATORS(classname) \ + +#define DECLARE_STL_SET(valuetype, comparefct, classname) \ + typedef ::std::set< valuetype, comparefct > classname; \ + DECLARE_STL_ITERATORS(classname) \ + +#endif // _COMPHELPER_STLTYPES_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/stlunosequence.hxx b/include/comphelper/stlunosequence.hxx new file mode 100644 index 000000000000..c7b776f78d6e --- /dev/null +++ b/include/comphelper/stlunosequence.hxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_STLUNOITERATOR_HXX +#define _COMPHELPER_STLUNOITERATOR_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <sal/types.h> + + +namespace comphelper +{ + /** + @short stl-container-like access to an existing ::com::sun::star::uno::Sequence + @descr These template functions allows using an existing + ::com::sun::star::uno::Sequence using stl algorithms. They provides + standard-compliant mutable random access iterators. Because random access + iterators are the most generic iterators defined by the stl, any stl algorithm + can be applied to the Sequence (excluding algorithms requiring output + iterators). + <p> + Example: (creating a ::std::list from a ::com::sun::star::uno::Sequence) + <code> + ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10); + ::std::list stl_list(stl_begin(aSeq), stl_end(aSeq)); + </code> + <p> + Example: (sorting ::com::sun::star::uno::Sequence inplace) + <code> + ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10); + ::std::sort(stl_begin(aSeq), stl_seq.end(aSeq)); + </code> + <p> + Example: (counting occurrences of 4711 in a ::com::sun::star::uno::Sequence) + <code> + ::com::sun::star::uno::Sequence<sal_Int32> aSeq(10); + sal_Int32 count = 0; + ::std::count(stl_begin(aSeq), stl_end(aSeq), 4711, count); + </code> + <p> + + @see http://www.sgi.com/tech/stl/Container.html + @see http://www.sgi.com/tech/stl/Sequence.html + @see http://www.sgi.com/tech/stl/RandomAccessIterator.html + */ + + template <typename V> + V* stl_begin(::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getArray(); } + + template <typename V> + V* stl_end(::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getArray() + rSeq.getLength(); } + + template <typename V> + const V* stl_begin(const ::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getConstArray(); } + + template <typename V> + const V* stl_end(const ::com::sun::star::uno::Sequence<V>& rSeq) + { return rSeq.getConstArray() + rSeq.getLength(); } +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/storagehelper.hxx b/include/comphelper/storagehelper.hxx new file mode 100644 index 000000000000..093038e6e5ed --- /dev/null +++ b/include/comphelper/storagehelper.hxx @@ -0,0 +1,200 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef COMPHELPER_STORAGEHELPER_HXX +#define COMPHELPER_STORAGEHELPER_HXX + +#include <boost/scoped_ptr.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/embed/ElementModes.hpp> +#include "comphelper/comphelperdllapi.h" + + +#define PACKAGE_STORAGE_FORMAT_STRING OUString( "PackageFormat" ) +#define ZIP_STORAGE_FORMAT_STRING OUString( "ZipFormat" ) +#define OFOPXML_STORAGE_FORMAT_STRING OUString( "OFOPXMLFormat" ) + +#define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 OUString( "PackageSHA256UTF8EncryptionKey" ) +#define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 OUString( "PackageSHA1UTF8EncryptionKey" ) +#define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 OUString( "PackageSHA1MS1252EncryptionKey" ) + +namespace com { namespace sun { namespace star { + namespace beans { struct NamedValue; } + namespace embed { class XStorage; } + namespace io { + class XInputStream; + class XOutputStream; + class XStream; + } + namespace lang { class XSingleServiceFactory; } + namespace uno { class XComponentContext; } +} } } + +namespace comphelper { + +// Unfortunately - the impl.s of XStorage like to invalidate all +// their sub streams and storages when you release references, so +// it is necessary to keep references to all storages down the +// path - this is 'beautiful' (TM). So we need this ugly hack: +class COMPHELPER_DLLPUBLIC LifecycleProxy +{ +private: + class Impl; +public: + ::boost::scoped_ptr<Impl> m_pBadness; + LifecycleProxy(); + ~LifecycleProxy(); + // commit the storages: necessary for writes to streams to take effect! + void commitStorages(); +}; + +class COMPHELPER_DLLPUBLIC OStorageHelper +{ +public: + static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > + GetStorageFactory( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > + GetFileSystemStorageFactory( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetTemporaryStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + throw ( ::com::sun::star::uno::Exception ); + + /// this one will only return Storage + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageFromURL( + const OUString& aURL, + sal_Int32 nStorageMode, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + throw ( ::com::sun::star::uno::Exception ); + + /// this one will return either Storage or FileSystemStorage + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageFromURL2( + const OUString& aURL, + sal_Int32 nStorageMode, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageFromInputStream( + const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageFromStream( + const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream, + sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() ) + throw ( ::com::sun::star::uno::Exception ); + + static void CopyInputToOutput( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInput, + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > + GetInputStreamFromURL( + const OUString& aURL, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& context ) + throw ( ::com::sun::star::uno::Exception ); + + static void SetCommonStorageEncryptionData( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) + throw ( ::com::sun::star::uno::Exception ); + + // the following method supports only storages of OOo formats + static sal_Int32 GetXStorageFormat( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageOfFormatFromURL( + const OUString& aFormat, + const OUString& aURL, + sal_Int32 nStorageMode, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >(), + sal_Bool bRepairStorage = sal_False ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageOfFormatFromInputStream( + const OUString& aFormat, + const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >(), + sal_Bool bRepairStorage = sal_False ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageOfFormatFromStream( + const OUString& aFormat, + const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream, + sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext + = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >(), + sal_Bool bRepairStorage = sal_False ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > + CreatePackageEncryptionData( + const OUString& aPassword ); + + static sal_Bool IsValidZipEntryFileName( const OUString& aName, sal_Bool bSlashAllowed ); + static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); + + static sal_Bool PathHasSegment( const OUString& aPath, const OUString& aSegment ); + + // Methods to allow easy use of hierachical names inside storages + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageAtPath( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > &xStorage, + const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy &rNastiness ); + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStreamAtPath( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > &xStorage, + const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy &rNastiness ); + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStreamAtPackageURL( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > &xStorage, + const OUString& rURL, sal_uInt32 const nOpenMode, + LifecycleProxy & rNastiness ); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/streamsection.hxx b/include/comphelper/streamsection.hxx new file mode 100644 index 000000000000..40ea508f888b --- /dev/null +++ b/include/comphelper/streamsection.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_STREAMSECTION_HXX_ +#define _COMPHELPER_STREAMSECTION_HXX_ + +#include <com/sun/star/io/XMarkableStream.hpp> +#include <com/sun/star/io/XDataInputStream.hpp> +#include <com/sun/star/io/XDataOutputStream.hpp> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +/** implements handling for compatibly reading/writing data from/into an input/output stream. + data written in a block secured by this class should be readable by older versions which + use the same mechanism. + + @author Frank Schoenheit + @since 00/26/05 +*/ + +class COMPHELPER_DLLPUBLIC OStreamSection +{ + staruno::Reference< stario::XMarkableStream > m_xMarkStream; + staruno::Reference< stario::XDataInputStream > m_xInStream; + staruno::Reference< stario::XDataOutputStream > m_xOutStream; + + sal_Int32 m_nBlockStart; + sal_Int32 m_nBlockLen; + +public: + /** starts reading of a "skippable" section of data within the given input stream<BR> + @param _rxInput the stream to read from. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + */ + OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput); + + /** starts writing of a "skippable" section of data into the given output stream + @param _rxOutput the stream the stream to write to. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + @param _nPresumedLength estimation for the length of the upcoming section. If greater 0, this + value will be written as section length and corrected (in the dtor) only if + needed. If you know how much bytes you are about to write, you may + want to use this param, saving some stream operations this way. + */ + OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0); + + /** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR> + If constructed for reading, any remaining bytes 'til the end of the section will be skipped. + */ + ~OStreamSection(); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_STREAMSECTION_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/string.hxx b/include/comphelper/string.hxx new file mode 100644 index 000000000000..85b0816b895e --- /dev/null +++ b/include/comphelper/string.hxx @@ -0,0 +1,466 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef INCLUDED_COMPHELPER_STRING_HXX +#define INCLUDED_COMPHELPER_STRING_HXX + +#include "sal/config.h" + +#include <cstddef> +#include "comphelper/comphelperdllapi.h" +#include <sal/types.h> +#include <rtl/strbuf.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/i18n/XCollator.hpp> +#include <com/sun/star/i18n/XBreakIterator.hpp> + +// OUString helper functions that are not widespread or mature enough to +// go into the stable URE API: +namespace comphelper { namespace string { + +/** Compare an OString to a single char + + @param rIn The input OString + @param c The character to compare againsg + + @return true if rIn has one char and its equal to c + */ +inline bool equals(const OString& rIn, sal_Char c) +{ return rIn.getLength() == 1 && rIn[0] == c; } + +/** Compare an OUString to a single char + + @param rIn The input OUString + @param c The character to compare againsg + + @return true if rIn has one char and its equal to c + */ +inline bool equals(const OUString& rIn, sal_Unicode c) +{ return rIn.getLength() == 1 && rIn[0] == c; } + +/** Removes all occurrences of a character from within the source string + + @deprecated Use OString::replaceAll(OString(c), OString()) + instead. + + @param rIn The input OString + @param c The character to be removed + + @return The resulting OString + */ +inline OString remove(const OString &rIn, + sal_Char c) +{ return rIn.replaceAll(OString(c), OString()); } + +/** Removes all occurrences of a character from within the source string + + @deprecated Use + OUString::replaceAll(OUString(c), OUString()) instead. + + @param rIn The input OUString + @param c The character to be removed + + @return The resulting OUString + */ +inline OUString remove(const OUString &rIn, + sal_Unicode c) +{ return rIn.replaceAll(OUString(c), OUString()); } + +/** Strips occurrences of a character from the start of the source string + + @param rIn The input OString + @param c The character to be stripped from the start + + @return The resulting OString + */ +COMPHELPER_DLLPUBLIC OString stripStart(const OString &rIn, + sal_Char c); + +/** Strips occurrences of a character from the start of the source string + + @param rIn The input OUString + @param c The character to be stripped from the start + + @return The resulting OUString + */ +COMPHELPER_DLLPUBLIC OUString stripStart(const OUString &rIn, + sal_Unicode c); + +/** Strips occurrences of a character from the end of the source string + + @param rIn The input OString + @param c The character to be stripped from the end + + @return The resulting OString + */ +COMPHELPER_DLLPUBLIC OString stripEnd(const OString &rIn, + sal_Char c); + +/** Strips occurrences of a character from the end of the source string + + @param rIn The input OUString + @param c The character to be stripped from the end + + @return The resulting OUString + */ +COMPHELPER_DLLPUBLIC OUString stripEnd(const OUString &rIn, + sal_Unicode c); + +/** Strips occurrences of a character from the start and end of the source string + + @param rIn The input OString + @param c The character to be stripped from the start and end + + @return The resulting OString + */ +COMPHELPER_DLLPUBLIC OString strip(const OString &rIn, + sal_Char c); + +/** Strips occurrences of a character from the start and end of the source string + + @param rIn The input OUString + @param c The character to be stripped from the start and end + + @return The resulting OUString + */ +COMPHELPER_DLLPUBLIC OUString strip(const OUString &rIn, + sal_Unicode c); + +/** Returns a token in an OString + + @deprecated Use OString::getToken(nToken, cTok) instead. + + @param rIn the input OString + @param nToken the number of the token to return + @param cTok the character which seperate the tokens. + @return the token if token is negative or doesn't exist an empty token + is returned +*/ +inline OString getToken(const OString &rIn, + sal_Int32 nToken, sal_Char cTok) SAL_THROW(()) +{ + return rIn.getToken(nToken, cTok); +} + +/** Returns a token in an OUString + + @deprecated Use OUString::getToken(nToken, cTok) instead. + + @param rIn the input OUString + @param nToken the number of the token to return + @param cTok the character which seperate the tokens. + @return the token if token is negative or doesn't exist an empty token + is returned +*/ +inline OUString getToken(const OUString &rIn, + sal_Int32 nToken, sal_Unicode cTok) SAL_THROW(()) +{ + return rIn.getToken(nToken, cTok); +} + +/** Returns number of tokens in an OUString + + @param rIn the input OString + @param cTok the character which seperate the tokens. + @return the number of tokens +*/ +COMPHELPER_DLLPUBLIC sal_Int32 getTokenCount(const OString &rIn, sal_Char cTok); + +/** Returns number of tokens in an OUString + + @param rIn the input OUString + @param cTok the character which seperate the tokens. + @return the number of tokens +*/ +COMPHELPER_DLLPUBLIC sal_Int32 getTokenCount(const OUString &rIn, sal_Unicode cTok); + +/** Reverse an OUString + + @param rIn the input OUString + @return the reversed input +*/ +COMPHELPER_DLLPUBLIC OUString reverseString(const OUString &rStr); + +/** Reverse an OString + + @param rIn the input OString + @return the reversed input +*/ +COMPHELPER_DLLPUBLIC OString reverseString(const OString &rStr); + + +namespace detail +{ + template<typename B> B& truncateToLength(B& rBuffer, sal_Int32 nLen) + { + if (nLen < rBuffer.getLength()) + rBuffer.remove(nLen, rBuffer.getLength()-nLen); + return rBuffer; + } +} + +/** Truncate a buffer to a given length. + + If the StringBuffer has more characters than nLength it will be truncated + on the right to nLength characters. + + Has no effect if the StringBuffer is <= nLength + + @param rBuf StringBuffer to operate on + @param nLength Length to truncate the buffer to + + @return rBuf; + */ +COMPHELPER_DLLPUBLIC inline OStringBuffer& truncateToLength( + OStringBuffer& rBuffer, sal_Int32 nLength) SAL_THROW(()) +{ + return detail::truncateToLength(rBuffer, nLength); +} + +COMPHELPER_DLLPUBLIC inline OUStringBuffer& truncateToLength( + OUStringBuffer& rBuffer, sal_Int32 nLength) SAL_THROW(()) +{ + return detail::truncateToLength(rBuffer, nLength); +} + +namespace detail +{ + template<typename B, typename U> B& padToLength(B& rBuffer, sal_Int32 nLen, + U cFill = '\0') + { + sal_Int32 nOrigLen = rBuffer.getLength(); + if (nLen > nOrigLen) + { + rBuffer.setLength(nLen); + for (sal_Int32 i = nOrigLen; i < nLen; ++i) + rBuffer[i] = cFill; + } + return rBuffer; + } +} + +/** Pad a buffer to a given length using a given char. + + If the StringBuffer has less characters than nLength it will be expanded on + the right to nLength characters, with the expansion filled using cFill. + + Has no effect if the StringBuffer is >= nLength + + @param rBuf StringBuffer to operate on + @param nLength Length to pad the buffer to + @param cFill character to fill expansion with + + @return rBuf; + */ +COMPHELPER_DLLPUBLIC inline OStringBuffer& padToLength( + OStringBuffer& rBuffer, sal_Int32 nLength, + sal_Char cFill = '\0') SAL_THROW(()) +{ + return detail::padToLength(rBuffer, nLength, cFill); +} + +COMPHELPER_DLLPUBLIC inline OUStringBuffer& padToLength( + OUStringBuffer& rBuffer, sal_Int32 nLength, + sal_Unicode cFill = '\0') SAL_THROW(()) +{ + return detail::padToLength(rBuffer, nLength, cFill); +} + +/** Find any of a list of code units in the string. + @param rIn OUString to search + @param pChars 0-terminated array of sal_Unicode code units to search for + @param nPos start position + + @return position of first occurrence of any of the elements of pChars + or -1 if none of the code units occur in the string + */ +COMPHELPER_DLLPUBLIC sal_Int32 indexOfAny(OUString const& rIn, + sal_Unicode const*const pChars, sal_Int32 const nPos = 0); + +/** Convert a sequence of strings to a single comma separated string. + + Note that no escaping of commas or anything fancy is done. + + @param i_rSeq A list of strings to be concatenated. + + @return A single string containing the concatenation of the given + list, interspersed with the string ", ". + */ +COMPHELPER_DLLPUBLIC OUString convertCommaSeparated( + ::com::sun::star::uno::Sequence< OUString > const & i_rSeq); + +/** Convert a decimal string to a number. + + The string must be base-10, no sign but can contain any + codepoint listed in the "Number, Decimal Digit" Unicode + category. + + No verification is made about the validity of the string, + passing string not containing decimal digit code points + gives unspecified results + + If your string is guaranteed to contain only ASCII digit + use OUString::toInt32 instead. + + @param str The string to convert containing only decimal + digit codepoints. + + @return The value of the string as an int32. + */ +COMPHELPER_DLLPUBLIC sal_uInt32 decimalStringToNumber( + OUString const & str ); + +/** Convert a single comma separated string to a sequence of strings. + + Note that no escaping of commas or anything fancy is done. + + @param i_rString A string containing comma-separated words. + + @return A sequence of strings resulting from splitting the given + string at ',' tokens and stripping whitespace. + */ +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< OUString > + convertCommaSeparated( OUString const & i_rString ); + +/** + Compares two strings using natural order. + + For non digit characters, the comparison use the same algorithm as + rtl_str_compare. When a number is encountered during the comparison, + natural order is used. Thus, Heading 10 will be considered as greater + than Heading 2. Numerical comparison is done using decimal representation. + + Beware that "MyString 001" and "MyString 1" will be considered as equal + since leading 0 are meaningless. + + @param str the object to be compared. + @return 0 - if both strings are equal + < 0 - if this string is less than the string argument + > 0 - if this string is greater than the string argument +*/ +COMPHELPER_DLLPUBLIC sal_Int32 compareNatural( const OUString &rLHS, const OUString &rRHS, + const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > &rCollator, + const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > &rBI, + const ::com::sun::star::lang::Locale &rLocale ); + +class COMPHELPER_DLLPUBLIC NaturalStringSorter +{ +private: + ::com::sun::star::lang::Locale m_aLocale; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > m_xCollator; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > m_xBI; +public: + NaturalStringSorter( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rContext, + const ::com::sun::star::lang::Locale &rLocale); + sal_Int32 compare(const OUString &rLHS, const OUString &rRHS) const + { + return compareNatural(rLHS, rRHS, m_xCollator, m_xBI, m_aLocale); + } + const ::com::sun::star::lang::Locale& getLocale() const { return m_aLocale; } +}; + +/** Determine if an OString contains solely ASCII numeric digits + + @param rString An OString + + @return false if string contains any characters outside + the ASCII '0'-'9' range + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const OString &rString); + +/** Determine if an OUString contains solely ASCII numeric digits + + @param rString An OUString + + @return false if string contains any characters outside + the ASCII '0'-'9' range + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const OUString &rString); + +COMPHELPER_DLLPUBLIC inline bool isdigitAscii(sal_Unicode c) +{ + return ((c >= '0') && (c <= '9')); +} + +COMPHELPER_DLLPUBLIC inline bool isxdigitAscii(sal_Unicode c) +{ + return isdigitAscii(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); +} + +COMPHELPER_DLLPUBLIC inline bool islowerAscii(sal_Unicode c) +{ + return ((c >= 'a') && (c <= 'z')); +} + +COMPHELPER_DLLPUBLIC inline bool isupperAscii(sal_Unicode c) +{ + return ((c >= 'A') && (c <= 'Z')); +} + +COMPHELPER_DLLPUBLIC inline bool isalphaAscii(sal_Unicode c) +{ + return islowerAscii(c) || isupperAscii(c); +} + +COMPHELPER_DLLPUBLIC inline bool isalnumAscii(sal_Unicode c) +{ + return isalphaAscii(c) || isdigitAscii(c); +} + +//============================================================ +//= a helper for static ascii pseudo-unicode strings +//============================================================ +struct COMPHELPER_DLLPUBLIC ConstAsciiString +{ + const sal_Char* ascii; + sal_Int32 length; + + operator OUString() const + { + return OUString(ascii, length, RTL_TEXTENCODING_ASCII_US); + } +}; + +} } + +#ifdef RTL_FAST_STRING +// TODO The whole ConstAsciiString class should probably be dumped +// and replaced with plain 'const char[]'. +namespace rtl +{ +template<> +struct ToStringHelper< comphelper::string::ConstAsciiString > + { + static int length( const comphelper::string::ConstAsciiString& str ) { return str.length; } + static sal_Unicode* addData( sal_Unicode* buffer, const comphelper::string::ConstAsciiString& str ) { return addDataLiteral( buffer, str.ascii, str.length ); } + static const bool allowOStringConcat = false; + static const bool allowOUStringConcat = true; + }; +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/synchronousdispatch.hxx b/include/comphelper/synchronousdispatch.hxx new file mode 100644 index 000000000000..efeffea6b4eb --- /dev/null +++ b/include/comphelper/synchronousdispatch.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_SYNCHRONOUSDISPATCH_HXX +#define _COMPHELPER_SYNCHRONOUSDISPATCH_HXX + +#include "comphelper/comphelperdllapi.h" + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" + +#include "com/sun/star/beans/PropertyValue.hpp" + +namespace com { namespace sun { namespace star { + namespace uno { + class XInterface; } + namespace lang { + class XComponent; } +} } } + + +//........................................................................ +namespace comphelper +{ +//........................................................................ + + //==================================================================== + //= SynchronousDispatch + //==================================================================== + /** a helper class for working with the dispatch interface replacing + loadComponentFromURL + */ + class SynchronousDispatch + { + public: + static COMPHELPER_DLLPUBLIC com::sun::star::uno::Reference< com::sun::star::lang::XComponent > dispatch( + const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > &xStartPoint, + const OUString &sURL, + const OUString &sTarget, + const sal_Int32 nFlags, + const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &lArguments ); + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // _COMPHELPER_SYNCHRONOUSDISPATCH_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/syntaxhighlight.hxx b/include/comphelper/syntaxhighlight.hxx new file mode 100644 index 000000000000..ef1a9486a6bf --- /dev/null +++ b/include/comphelper/syntaxhighlight.hxx @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_SYNTAXHIGHLIGHT_HXX +#define _COMPHELPER_SYNTAXHIGHLIGHT_HXX + +#include <vector> +#include <rtl/ustring.hxx> + +#include <comphelper/comphelperdllapi.h> + + +#if defined CDECL +#undef CDECL +#endif + +// for the bsearch +#ifdef WNT +#define CDECL _cdecl +#endif +#if defined(UNX) +#define CDECL +#endif +#ifdef UNX +#include <sys/resource.h> +#endif + + +// Token-Typen TT_... +enum TokenTypes +{ + TT_UNKNOWN, + TT_IDENTIFIER, + TT_WHITESPACE, + TT_NUMBER, + TT_STRING, + TT_EOL, + TT_COMMENT, + TT_ERROR, + TT_OPERATOR, + TT_KEYWORDS, + TT_PARAMETER +}; + +struct HighlightPortion { sal_uInt16 nBegin; sal_uInt16 nEnd; TokenTypes tokenType; }; + + +typedef std::vector<HighlightPortion> HighlightPortions; + +///////////////////////////////////////////////////////////////////////// +// Auxiliary class to support JavaScript modules, next to find functions which +// will later will be used for syntax highlighting + +// Flags for character properties +#define CHAR_START_IDENTIFIER 0x0001 +#define CHAR_IN_IDENTIFIER 0x0002 +#define CHAR_START_NUMBER 0x0004 +#define CHAR_IN_NUMBER 0x0008 +#define CHAR_IN_HEX_NUMBER 0x0010 +#define CHAR_IN_OCT_NUMBER 0x0020 +#define CHAR_START_STRING 0x0040 +#define CHAR_OPERATOR 0x0080 +#define CHAR_SPACE 0x0100 +#define CHAR_EOL 0x0200 + +#define CHAR_EOF 0x00 + + +// Language mode of the Highlighter (possibly to be refined later with keyword +// lists, C comment flags) +enum HighlighterLanguage +{ + HIGHLIGHT_BASIC, + HIGHLIGHT_SQL +}; + +class SimpleTokenizer_Impl +{ + HighlighterLanguage aLanguage; + // Character information tables + sal_uInt16 aCharTypeTab[256]; + + const sal_Unicode* mpStringBegin; + const sal_Unicode* mpActualPos; + + // Lines and columns + sal_uInt32 nLine; + sal_uInt32 nCol; + + sal_Unicode peekChar( void ) { return *mpActualPos; } + sal_Unicode getChar( void ) { nCol++; return *mpActualPos++; } + + // Auxiliary function: testing of the character flags + sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ); + + // Get new token, EmptyString == nothing more over there + sal_Bool getNextToken( /*out*/TokenTypes& reType, + /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ); + + const char** ppListKeyWords; + sal_uInt16 nKeyWordCount; + +public: + SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); + ~SimpleTokenizer_Impl( void ); + + sal_uInt16 parseLine( sal_uInt32 nLine, const OUString* aSource ); + void getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine, + /*out*/HighlightPortions& portions ); + void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); +}; + + +//*** SyntaxHighlighter Class *** +// Concept: the Highlighter will be notified of all changes in the source +// (notifyChange) and returns the caller the range of lines, which based on the +// changes, need to be highlighted again. For this the Highlighter marks all +// lines internally whether or not C comments begin or end. +class COMPHELPER_DLLPUBLIC SyntaxHighlighter +{ + HighlighterLanguage eLanguage; + SimpleTokenizer_Impl* m_pSimpleTokenizer; + char* m_pKeyWords; + sal_uInt16 m_nKeyWordCount; + +// void initializeKeyWords( HighlighterLanguage eLanguage ); + +public: + SyntaxHighlighter( void ); + ~SyntaxHighlighter( void ); + + // (Re-)initialize Highlighter. The line-table will be completely erased, + // meaning that on completion an empty Source is assumed. + // notifyChange() can only be given line 0 + void initialize( HighlighterLanguage eLanguage_ ); + + void notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference, + const OUString* pChangedLines, sal_uInt32 nArrayLength); + + void getHighlightPortions( sal_uInt32 nLine, const OUString& rLine, + HighlightPortions& pPortions ); + + HighlighterLanguage GetLanguage() { return eLanguage;} +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/types.hxx b/include/comphelper/types.hxx new file mode 100644 index 000000000000..66c6a9e0bcfb --- /dev/null +++ b/include/comphelper/types.hxx @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_TYPES_HXX_ +#define _COMPHELPER_TYPES_HXX_ + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include "comphelper/comphelperdllapi.h" +#include "cppu/unotype.hxx" + +namespace com { namespace sun { namespace star { namespace awt { + struct FontDescriptor; +} } } } + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starawt = ::com::sun::star::awt; + namespace starlang = ::com::sun::star::lang; + + typedef staruno::Reference< staruno::XInterface > InterfaceRef; + typedef staruno::Sequence< OUString > StringSequence; + + //------------------------------------------------------------------------- + /** compare the two given Anys + The comparison is deep, means if one of the Any's contains an Any which contains an Any ..., this is resolved <br/> + Other types recognized currently : FontDescriptor, ::com::sun::star::util::Date/Tim/DateTime, staruno::Sequence<sal_Int8> + */ + COMPHELPER_DLLPUBLIC sal_Bool compare(const staruno::Any& rLeft, const staruno::Any& rRight); + + //------------------------------------------------------------------------- + /** compare two FontDescriptor's + */ + COMPHELPER_DLLPUBLIC sal_Bool operator ==(const starawt::FontDescriptor& _rLeft, const starawt::FontDescriptor& _rRight); + inline sal_Bool operator !=(const starawt::FontDescriptor& _rLeft, const starawt::FontDescriptor& _rRight) + { + return !(_rLeft == _rRight); + } + + //------------------------------------------------------------------------- + /// returns sal_True if objects of the types given are "compatible" + COMPHELPER_DLLPUBLIC sal_Bool isAssignableFrom(const staruno::Type& _rAssignable, const staruno::Type& _rFrom); + + //------------------------------------------------------------------------- + /** just a small shortcut ... + check if a type you have at hand at runtime is equal to another type you have at compile time + if all our compiler would accept function calls with explicit template arguments (like + isA<classFoo>(runtimeType)), we wouldn't need the second parameter. But unfortunally at + least the current solaris compiler doesn't allow this .... + So this function is nearly senseless .... + */ + template <class TYPE> + sal_Bool isA(const staruno::Type& _rType, TYPE* pDummy) + { + return _rType.equals(cppu::getTypeFavourUnsigned(pDummy)); + } + + //------------------------------------------------------------------------- + /** check if a type you have at hand at runtime is equal to another type you have at compile time + same comment as for the other isA .... + */ + template <class TYPE> + sal_Bool isA(const staruno::Any& _rVal, TYPE* pDummy) + { + return _rVal.getValueType().equals( + cppu::getTypeFavourUnsigned(pDummy)); + } + + //------------------------------------------------------------------------- + /** check if a type you have at hand at runtime is equal to another type you have at compile time + */ + template <class TYPE> + sal_Bool isAReference(const staruno::Any& _rVal, TYPE*) + { + return _rVal.getValueType().equals( + cppu::getTypeFavourUnsigned( + static_cast<staruno::Reference<TYPE>*>(NULL))); + } + + //------------------------------------------------------------------------- + /** ask the given object for an XComponent interface and dispose on it + */ + template <class TYPE> + void disposeComponent(staruno::Reference<TYPE>& _rxComp) + { + staruno::Reference<starlang::XComponent> xComp(_rxComp, staruno::UNO_QUERY); + if (xComp.is()) + { + xComp->dispose(); + _rxComp = NULL; + } + } + //------------------------------------------------------------------------- + template <class TYPE> + sal_Bool getImplementation(TYPE*& _pObject, const staruno::Reference< staruno::XInterface >& _rxIFace) + { + _pObject = NULL; + staruno::Reference< starlang::XUnoTunnel > xTunnel(_rxIFace, staruno::UNO_QUERY); + if (xTunnel.is()) + _pObject = reinterpret_cast< TYPE* >(xTunnel->getSomething(TYPE::getUnoTunnelImplementationId())); + + return (_pObject != NULL); + } + + + //------------------------------------------------------------------------- + /** get a com::sun::star::awt::FontDescriptor that is fully initialized with + the XXX_DONTKNOW enum values (which isn't the case if you instantiate it + via the default constructor) + */ + COMPHELPER_DLLPUBLIC starawt::FontDescriptor getDefaultFont(); + + /** examine a sequence for the <type scope="com.sun.star.uno">Type</type> of it's elements. + */ + COMPHELPER_DLLPUBLIC staruno::Type getSequenceElementType(const staruno::Type& _rSequenceType); + +//========================================================================= +//= replacement of the former UsrAny.getXXX methods + + // may be used if you need the return value just as temporary, else it's may be too inefficient .... + + // no, we don't use templates here. This would lead to a lot of implicit uses of the conversion methods, + // which would be difficult to trace ... + + COMPHELPER_DLLPUBLIC sal_Int64 getINT64(const staruno::Any& _rAny); + COMPHELPER_DLLPUBLIC sal_Int32 getINT32(const staruno::Any& _rAny); + COMPHELPER_DLLPUBLIC sal_Int16 getINT16(const staruno::Any& _rAny); + COMPHELPER_DLLPUBLIC double getDouble(const staruno::Any& _rAny); + COMPHELPER_DLLPUBLIC float getFloat(const staruno::Any& _rAny); + COMPHELPER_DLLPUBLIC OUString getString(const staruno::Any& _rAny); + COMPHELPER_DLLPUBLIC sal_Bool getBOOL(const staruno::Any& _rAny); + + COMPHELPER_DLLPUBLIC sal_Int32 getEnumAsINT32(const staruno::Any& _rAny) throw(starlang::IllegalArgumentException); + +//= replacement of some former UsrAny.setXXX methods - can be used with rvalues + inline void setBOOL(staruno::Any& _rAny, sal_Bool _b) + { _rAny.setValue(&_b, ::getBooleanCppuType()); } + +//= extension of ::cppu::makeAny() + inline staruno::Any makeBoolAny(sal_Bool _b) + { return staruno::Any(&_b, ::getBooleanCppuType()); } + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_TYPES_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/uno3.hxx b/include/comphelper/uno3.hxx new file mode 100644 index 000000000000..1b83c73f4f25 --- /dev/null +++ b/include/comphelper/uno3.hxx @@ -0,0 +1,275 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef _COMPHELPER_UNO3_HXX_ +#define _COMPHELPER_UNO3_HXX_ + +#include <osl/interlck.h> +#include <rtl/instance.hxx> +#include <comphelper/types.hxx> +#include <com/sun/star/uno/XAggregation.hpp> +#include <comphelper/sequence.hxx> +#include <cppuhelper/typeprovider.hxx> + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//========================================================================= + + /// manipulate ref counts without calling acquire/release + inline oslInterlockedCount increment(oslInterlockedCount& _counter) { return osl_atomic_increment(&_counter); } + inline oslInterlockedCount decrement(oslInterlockedCount& _counter) { return osl_atomic_decrement(&_counter); } + +//========================================================================= + + /** used for declaring UNO3-Defaults, i.e. acquire/release + */ + #define DECLARE_UNO3_DEFAULTS(classname, baseclass) \ + virtual void SAL_CALL acquire() throw() { baseclass::acquire(); } \ + virtual void SAL_CALL release() throw() { baseclass::release(); } \ + void SAL_CALL PUT_SEMICOLON_AT_THE_END() + + /** used for declaring UNO3-Defaults, i.e. acquire/release if you want to forward all queryInterfaces to the base class, + (e.g. if you overload queryAggregation) + */ + #define DECLARE_UNO3_AGG_DEFAULTS(classname, baseclass) \ + virtual void SAL_CALL acquire() throw() { baseclass::acquire(); } \ + virtual void SAL_CALL release() throw() { baseclass::release(); } \ + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException) \ + { return baseclass::queryInterface(_rType); } \ + void SAL_CALL PUT_SEMICOLON_AT_THE_END() + + /** Use this macro to forward XComponent methods to base class + + When using the ::cppu::WeakComponentImplHelper base classes to + implement a UNO interface, a problem occurs when the interface + itself already derives from XComponent (like e.g. awt::XWindow + or awt::XControl): ::cppu::WeakComponentImplHelper is then + still abstract. Using this macro in the most derived class + definition provides overrides for the XComponent methods, + forwarding them to the given baseclass. + + @param classname + Name of the class this macro is issued within + + @param baseclass + Name of the baseclass that should have the XInterface methods + forwarded to - that's usually the WeakComponentImplHelperN base + + @param implhelper + Name of the baseclass that should have the XComponent methods + forwarded to - in the case of the WeakComponentImplHelper, + that would be ::cppu::WeakComponentImplHelperBase + */ + #define DECLARE_UNO3_XCOMPONENT_DEFAULTS(classname, baseclass, implhelper) \ + virtual void SAL_CALL acquire() throw() { baseclass::acquire(); } \ + virtual void SAL_CALL release() throw() { baseclass::release(); } \ + virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException) \ + { \ + implhelper::dispose(); \ + } \ + virtual void SAL_CALL addEventListener( \ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + implhelper::addEventListener(xListener); \ + } \ + virtual void SAL_CALL removeEventListener( \ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + implhelper::removeEventListener(xListener); \ + } \ + void SAL_CALL PUT_SEMICOLON_AT_THE_END() + + + /** Use this macro to forward XComponent methods to base class + + When using the ::cppu::WeakComponentImplHelper base classes to + implement a UNO interface, a problem occurs when the interface + itself already derives from XComponent (like e.g. awt::XWindow + or awt::XControl): ::cppu::WeakComponentImplHelper is then + still abstract. Using this macro in the most derived class + definition provides overrides for the XComponent methods, + forwarding them to the given baseclass. + + @param classname + Name of the class this macro is issued within + + @param baseclass + Name of the baseclass that should have the XInterface methods + forwarded to - that's usually the WeakComponentImplHelperN base + + @param implhelper + Name of the baseclass that should have the XComponent methods + forwarded to - in the case of the WeakComponentImplHelper, + that would be ::cppu::WeakComponentImplHelperBase + */ + #define DECLARE_UNO3_XCOMPONENT_AGG_DEFAULTS(classname, baseclass, implhelper) \ + virtual void SAL_CALL acquire() throw() { baseclass::acquire(); } \ + virtual void SAL_CALL release() throw() { baseclass::release(); } \ + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException) \ + { return baseclass::queryInterface(_rType); } \ + virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException) \ + { \ + implhelper::dispose(); \ + } \ + virtual void SAL_CALL addEventListener( \ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + implhelper::addEventListener(xListener); \ + } \ + virtual void SAL_CALL removeEventListener( \ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > const & xListener ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + implhelper::removeEventListener(xListener); \ + } \ + void SAL_CALL PUT_SEMICOLON_AT_THE_END() + + + //===================================================================== + //= deriving from multiple XInterface-derived classes + //===================================================================== + //= forwarding/merging XInterface funtionality + //===================================================================== + #define DECLARE_XINTERFACE( ) \ + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); \ + virtual void SAL_CALL acquire() throw(); \ + virtual void SAL_CALL release() throw(); + + #define IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \ + void SAL_CALL classname::acquire() throw() { refcountbase::acquire(); } \ + void SAL_CALL classname::release() throw() { refcountbase::release(); } + + #define IMPLEMENT_FORWARD_XINTERFACE2( classname, refcountbase, baseclass2 ) \ + IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \ + ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + ::com::sun::star::uno::Any aReturn = refcountbase::queryInterface( _rType ); \ + if ( !aReturn.hasValue() ) \ + aReturn = baseclass2::queryInterface( _rType ); \ + return aReturn; \ + } + + #define IMPLEMENT_FORWARD_XINTERFACE3( classname, refcountbase, baseclass2, baseclass3 ) \ + IMPLEMENT_FORWARD_REFCOUNT( classname, refcountbase ) \ + ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + ::com::sun::star::uno::Any aReturn = refcountbase::queryInterface( _rType ); \ + if ( !aReturn.hasValue() ) \ + { \ + aReturn = baseclass2::queryInterface( _rType ); \ + if ( !aReturn.hasValue() ) \ + aReturn = baseclass3::queryInterface( _rType ); \ + } \ + return aReturn; \ + } + + //===================================================================== + //= forwarding/merging XTypeProvider funtionality + //===================================================================== + #define DECLARE_XTYPEPROVIDER( ) \ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); \ + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); + + #define IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) \ + namespace \ + { \ + class the##classname##ImplementationId : public rtl::Static< ::cppu::OImplementationId, the##classname##ImplementationId> {}; \ + } \ + ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId( ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + return the##classname##ImplementationId::get().getImplementationId(); \ + } + + #define IMPLEMENT_FORWARD_XTYPEPROVIDER2( classname, baseclass1, baseclass2 ) \ + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes( ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + return ::comphelper::concatSequences( \ + baseclass1::getTypes(), \ + baseclass2::getTypes() \ + ); \ + } \ + \ + IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) + + #define IMPLEMENT_FORWARD_XTYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \ + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes( ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + return ::comphelper::concatSequences( \ + baseclass1::getTypes(), \ + baseclass2::getTypes(), \ + baseclass3::getTypes() \ + ); \ + } \ + \ + IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) + +//========================================================================= + + /** ask for an iface of an aggregated object + usage:<br/> + Reference<XFoo> xFoo;<br/> + if (query_aggregation(xAggregatedObject, xFoo))<br/> + .... + */ + template <class iface> + sal_Bool query_aggregation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation >& _rxAggregate, ::com::sun::star::uno::Reference<iface>& _rxOut) + { + _rxOut = static_cast<iface*>(NULL); + if (_rxAggregate.is()) + { + ::com::sun::star::uno::Any aCheck = _rxAggregate->queryAggregation( + iface::static_type()); + if (aCheck.hasValue()) + _rxOut = *(::com::sun::star::uno::Reference<iface>*)aCheck.getValue(); + } + return _rxOut.is(); + } + + /** ask for an iface of an object + usage:<br/> + Reference<XFoo> xFoo;<br/> + if (query_interface(xAnything, xFoo))<br/> + .... + */ + template <class iface> + sal_Bool query_interface(const InterfaceRef& _rxObject, ::com::sun::star::uno::Reference<iface>& _rxOut) + { + _rxOut = static_cast<iface*>(NULL); + if (_rxObject.is()) + { + ::com::sun::star::uno::Any aCheck = _rxObject->queryInterface( + iface::static_type()); + if(aCheck.hasValue()) + { + _rxOut = *(::com::sun::star::uno::Reference<iface>*)aCheck.getValue(); + return _rxOut.is(); + } + } + return sal_False; + } + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_UNO3_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/unwrapargs.hxx b/include/comphelper/unwrapargs.hxx new file mode 100644 index 000000000000..c4885f3883d9 --- /dev/null +++ b/include/comphelper/unwrapargs.hxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_UNWRAPARGS_HXX_INCLUDED +#define COMPHELPER_UNWRAPARGS_HXX_INCLUDED + +#include "rtl/ustrbuf.hxx" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/lang/IllegalArgumentException.hpp" +#include "boost/optional.hpp" +#include "boost/preprocessor/cat.hpp" +#include "boost/preprocessor/repetition.hpp" +#include "boost/preprocessor/arithmetic/add.hpp" +#include "cppu/unotype.hxx" + +namespace comphelper { + +// +// generating helper functions to unwrap the service's argument sequence: +// + +/// @internal +namespace detail { + +template <typename T> +inline void extract( + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> const& seq, + sal_Int32 nArg, T & v, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> + const& xErrorContext ) +{ + if (nArg >= seq.getLength()) { + throw ::com::sun::star::lang::IllegalArgumentException( + OUString( "No such argument available!"), + xErrorContext, static_cast<sal_Int16>(nArg) ); + } + if (! (seq[nArg] >>= v)) { + OUStringBuffer buf; + buf.append( "Cannot extract ANY { " ); + buf.append( seq[nArg].getValueType().getTypeName() ); + buf.append( " } to " ); + buf.append( ::cppu::UnoType<T>::get().getTypeName() ); + buf.append( static_cast<sal_Unicode>('!') ); + throw ::com::sun::star::lang::IllegalArgumentException( + buf.makeStringAndClear(), xErrorContext, + static_cast<sal_Int16>(nArg) ); + } +} + +template <typename T> +inline void extract( + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> const& seq, + sal_Int32 nArg, ::boost::optional<T> & v, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> + const& xErrorContext ) +{ + if (nArg < seq.getLength()) { + T t; + extract( seq, nArg, t, xErrorContext ); + v.reset( t ); + } +} + +} // namespace detail + +#define COMPHELPER_UNWRAPARGS_extract(z_, n_, unused_) \ + detail::extract( seq, n_, BOOST_PP_CAT(v, n_), xErrorContext ); +#define COMPHELPER_UNWRAPARGS_args(z_, n_, unused_) \ + BOOST_PP_CAT(T, n_) & BOOST_PP_CAT(v, n_) + +/** The following preprocessor repetitions generate functions like + + <pre> + template <typename T0, typename T1, ...> + inline void unwrapArgs( + uno::Sequence<uno::Any> const& seq, + T0 & v0, T1 & v1, ..., + css::uno::Reference<css::uno::XInterface> const& xErrorContext = + css::uno::Reference<css::uno::XInterface>() ); + </pre> + (full namespace qualification ::com::sun::star has been omitted + for brevity) + + which unwraps the passed sequence's elements, assigning them to the + referenced values. Specify optional arguments as boost::optional<T>. + If the length of the sequence is greater than the count of arguments, + then the latter sequence elements are ignored. + If too few arguments are given in the sequence and a missing argument is + no boost::optional<T>, then an lang::IllegalArgumentException is thrown + with the specified xErrorContext (defaults to null-ref). + + The maximum number of service declarations can be set by defining + COMPHELPER_UNWRAPARGS_MAX_ARGS; its default is 12. +*/ +#define COMPHELPER_UNWRAPARGS_make(z_, n_, unused_) \ +template < BOOST_PP_ENUM_PARAMS( BOOST_PP_ADD(n_, 1), typename T) > \ +inline void unwrapArgs( \ + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > const& seq, \ + BOOST_PP_ENUM(BOOST_PP_ADD(n_, 1), COMPHELPER_UNWRAPARGS_args, ~), \ + ::com::sun::star::uno::Reference< \ + ::com::sun::star::uno::XInterface> const& xErrorContext = \ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>() ) \ +{ \ + BOOST_PP_REPEAT(BOOST_PP_ADD(n_, 1), COMPHELPER_UNWRAPARGS_extract, ~) \ +} + +#ifndef COMPHELPER_UNWRAPARGS_MAX_ARGS +#define COMPHELPER_UNWRAPARGS_MAX_ARGS 12 +#endif + +BOOST_PP_REPEAT(COMPHELPER_UNWRAPARGS_MAX_ARGS, COMPHELPER_UNWRAPARGS_make, ~) + +#undef COMPHELPER_UNWRAPARGS_MAX_ARGS +#undef COMPHELPER_UNWRAPARGS_make +#undef COMPHELPER_UNWRAPARGS_args +#undef COMPHELPER_UNWRAPARGS_extract + +} // namespace comphelper + +#endif // ! defined(COMPHELPER_UNWRAPARGS_HXX_INCLUDED) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/weak.hxx b/include/comphelper/weak.hxx new file mode 100644 index 000000000000..126078adbf59 --- /dev/null +++ b/include/comphelper/weak.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ +#ifndef _COMPHELPER_WEAK_HXX_ +#define _COMPHELPER_WEAK_HXX_ + +#include "comphelper/comphelperdllapi.h" + +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <cppuhelper/weak.hxx> + +namespace comphelper +{ +/** Base class to implement an UNO object supporting types and weak references, i.e. the object can be held + weakly (by a ::com::sun::star::uno::WeakReference). + This implementation copes with reference counting. Upon last release(), the virtual dtor + is called. + + In addition to the features from cppu::OWeakObject, derivations from this class can + also used as a base class for ::cppu::ImplInheritanceHelper? +*/ +class COMPHELPER_DLLPUBLIC OWeakTypeObject : public ::cppu::OWeakObject, public ::com::sun::star::lang::XTypeProvider +{ +public: + OWeakTypeObject(); + virtual ~OWeakTypeObject(); + + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire() throw (); + virtual void SAL_CALL release() throw (); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); + +}; + +} + +#endif + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/weakbag.hxx b/include/comphelper/weakbag.hxx new file mode 100644 index 000000000000..b654baa2bda4 --- /dev/null +++ b/include/comphelper/weakbag.hxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef INCLUDED_COMPHELPER_WEAKBAG_HXX +#define INCLUDED_COMPHELPER_WEAKBAG_HXX + +#include "sal/config.h" + +#include <list> +#include "com/sun/star/uno/Reference.hxx" +#include "cppuhelper/weakref.hxx" +#include "osl/diagnose.h" + +namespace comphelper { + +/** + A bag of UNO weak references. +*/ +template< typename T > class WeakBag { +public: + /** + Add a new weak reference. + + The implementation keeps the amount of memory consumed linear in the + number of living references added, not linear in the number of total + references added. + + @param e + a non-null reference. + */ + void add(com::sun::star::uno::Reference< T > const & e) { + OSL_ASSERT(e.is()); + for (typename WeakReferenceList::iterator i(m_list.begin()); i != m_list.end();) { + if (com::sun::star::uno::Reference< T >(*i).is()) { + ++i; + } else { + i = m_list.erase(i); + } + } + m_list.push_back(com::sun::star::uno::WeakReference< T >(e)); + } + + /** + Remove a living reference. + + @return + a living reference, or null if there are none. + */ + com::sun::star::uno::Reference< T > remove() { + while (!m_list.empty()) { + com::sun::star::uno::Reference< T > r(m_list.front()); + m_list.pop_front(); + if (r.is()) { + return r; + } + } + return com::sun::star::uno::Reference< T >(); + } + +private: + typedef std::list< com::sun::star::uno::WeakReference< T > > WeakReferenceList; + + WeakReferenceList m_list; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/weakeventlistener.hxx b/include/comphelper/weakeventlistener.hxx new file mode 100644 index 000000000000..33defc8a36c9 --- /dev/null +++ b/include/comphelper/weakeventlistener.hxx @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#ifndef COMPHELPER_WEAKEVENTLISTENER_HXX +#define COMPHELPER_WEAKEVENTLISTENER_HXX + +#include <cppuhelper/compbase1.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/uno/XWeak.hpp> +#include <cppuhelper/weakref.hxx> +#include <comphelper/broadcasthelper.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + //===================================================================== + //= OWeakListenerAdapterBase + //===================================================================== + /** (the base for) an adapter which allows to add as listener to a foreign component, without + being held hard. + + <p>The idea is that this adapter is added as listener to a foreign component, which usually + holds it's listener hard. The adapter itself knows the real listener as weak reference, + thus not affecting it's life time.</p> + */ + class OWeakListenerAdapterBase : public OBaseMutex + { + private: + ::com::sun::star::uno::WeakReference< ::com::sun::star::uno::XInterface > + m_aListener; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + m_xBroadcaster; + + protected: + inline ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + getListener( ) const + { + return m_aListener.get(); + } + + inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& + getBroadcaster( ) const + { + return m_xBroadcaster; + } + + inline void resetListener( ) + { + m_aListener.clear(); + } + + + protected: + inline OWeakListenerAdapterBase( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak >& _rxListener, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxBroadcaster + ) + :m_aListener ( _rxListener ) + ,m_xBroadcaster ( _rxBroadcaster ) + { + } + + protected: + virtual ~OWeakListenerAdapterBase(); + }; + + + //===================================================================== + //= OWeakListenerAdapter + //===================================================================== + template< class BROADCASTER, class LISTENER > + /** yet another base for weak listener adapters, this time with some type safety + + <p>Note that derived classes need to overwrite all virtual methods of their interface + except XEventListener::disposing, and forward it to their master listener.</p> + + <p>Addtionally, derived classes need to add themself as listener to the broadcaster, + as this can't be done in a generic way</p> + */ + class OWeakListenerAdapter + :public ::cppu::WeakComponentImplHelper1 < LISTENER > + ,public OWeakListenerAdapterBase + { + protected: + /** ctor + <p>Note that derived classes still need to add themself as listener to the broadcaster, + as this can't be done in a generic way</p> + */ + OWeakListenerAdapter( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak >& _rxListener, + const ::com::sun::star::uno::Reference< BROADCASTER >& _rxBroadcaster + ); + + protected: + inline ::com::sun::star::uno::Reference< LISTENER > getListener( ) const + { + return ::com::sun::star::uno::Reference< LISTENER >( OWeakListenerAdapterBase::getListener(), ::com::sun::star::uno::UNO_QUERY ); + } + + // XEventListener overridables + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + protected: + // OComponentHelper overridables + // to be overridden, again - the derived class should revoke the listener from the broadcaster + virtual void SAL_CALL disposing( ) = 0; + }; + + //===================================================================== + //= OWeakEventListenerAdapter + //===================================================================== + typedef OWeakListenerAdapter < ::com::sun::star::lang::XComponent + , ::com::sun::star::lang::XEventListener + > OWeakEventListenerAdapter_Base; + /** the most simple listener adapter: for XEventListeners at XComponents + */ + class COMPHELPER_DLLPUBLIC OWeakEventListenerAdapter : public OWeakEventListenerAdapter_Base + { + public: + OWeakEventListenerAdapter( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak > _rxListener, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > _rxBroadcaster + ); + + // nothing to do except an own ctor - the forwarding of the "disposing" is already done + // in the base class + + protected: + using OWeakEventListenerAdapter_Base::disposing; + virtual void SAL_CALL disposing( ); + }; + + //===================================================================== + //= OWeakListenerAdapter + //===================================================================== + //--------------------------------------------------------------------- + template< class BROADCASTER, class LISTENER > + OWeakListenerAdapter< BROADCASTER, LISTENER >::OWeakListenerAdapter( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak >& _rxListener, + const ::com::sun::star::uno::Reference< BROADCASTER >& _rxBroadcaster + ) + : ::cppu::WeakComponentImplHelper1< LISTENER >( m_aMutex ) + , OWeakListenerAdapterBase( _rxListener, _rxBroadcaster ) + { + } + + //--------------------------------------------------------------------- + template< class BROADCASTER, class LISTENER > + void SAL_CALL OWeakListenerAdapter< BROADCASTER, LISTENER >::disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException) + { + ::com::sun::star::uno::Reference< LISTENER > xListener( getListener() ); + if ( xListener.is() ) + xListener->disposing( _rSource ); + } + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif// COMPHELPER_WEAKEVENTLISTENER_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/xmltools.hxx b/include/comphelper/xmltools.hxx new file mode 100644 index 000000000000..d8287dd4a89b --- /dev/null +++ b/include/comphelper/xmltools.hxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _XMLCHAFF_HXX +#define _XMLCHAFF_HXX + +#include <rtl/strbuf.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <comphelper/comphelperdllapi.h> + +namespace comphelper +{ + namespace xml + { + COMPHELPER_DLLPUBLIC OString makeXMLChaff(); + } +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |