diff options
Diffstat (limited to 'comphelper/inc')
111 files changed, 18490 insertions, 0 deletions
diff --git a/comphelper/inc/comphelper/ChainablePropertySet.hxx b/comphelper/inc/comphelper/ChainablePropertySet.hxx new file mode 100644 index 000000000000..0d36c2d10144 --- /dev/null +++ b/comphelper/inc/comphelper/ChainablePropertySet.hxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * 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_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; +} +namespace vos +{ + class IMutex; +} +/* + * 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 ) + * + * The implementations of getPropertyValues/setPropertyValues call + * lockMutex and _preGetValues/_preSetValues once before calling + * _getSingleValue/_setSingleValue for each property. After each + * property has been dealt with, _postGetValues/_postSetValues + * are called once. + * + * 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; + vos::IMutex *mpMutex; + ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySetInfo > mxInfo; + void lockMutex(); + void unlockMutex(); + + 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, vos::IMutex *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 ::rtl::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 ::rtl::OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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< ::rtl::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< ::rtl::OUString >& aPropertyNames ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< ::rtl::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< ::rtl::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 ::rtl::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< ::rtl::OUString >& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + }; +} +#endif + diff --git a/comphelper/inc/comphelper/ChainablePropertySetInfo.hxx b/comphelper/inc/comphelper/ChainablePropertySetInfo.hxx new file mode 100644 index 000000000000..76d181e21e7b --- /dev/null +++ b/comphelper/inc/comphelper/ChainablePropertySetInfo.hxx @@ -0,0 +1,77 @@ +/************************************************************************* + * + * 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_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() + throw(); + ChainablePropertySetInfo( PropertyInfo * pMap ) + throw(); + + virtual ~ChainablePropertySetInfo() + throw(); + + void add( PropertyInfo* pMap, sal_Int32 nCount = -1 ) + throw(); + void remove( const rtl::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 ::rtl::OUString& aName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) + throw(::com::sun::star::uno::RuntimeException); + }; +} +#endif diff --git a/comphelper/inc/comphelper/IdPropArrayHelper.hxx b/comphelper/inc/comphelper/IdPropArrayHelper.hxx new file mode 100644 index 000000000000..187c52fdc446 --- /dev/null +++ b/comphelper/inc/comphelper/IdPropArrayHelper.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * 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_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 diff --git a/comphelper/inc/comphelper/InlineContainer.hxx b/comphelper/inc/comphelper/InlineContainer.hxx new file mode 100644 index 000000000000..a5d80e263aac --- /dev/null +++ b/comphelper/inc/comphelper/InlineContainer.hxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * 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 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 >() + { + 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 diff --git a/comphelper/inc/comphelper/MasterPropertySet.hxx b/comphelper/inc/comphelper/MasterPropertySet.hxx new file mode 100644 index 000000000000..170b4f72db3b --- /dev/null +++ b/comphelper/inc/comphelper/MasterPropertySet.hxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * 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_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 vos +{ + class IMutex; +} +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; + vos::IMutex *mpMutex; + sal_uInt8 mnLastId; + SlaveMap maSlaveMap; + ::com::sun::star::uno::Reference < com::sun::star::beans::XPropertySetInfo > mxInfo; + void lockMutex(); + void unlockMutex(); + + 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, ::vos::IMutex *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 ::rtl::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 ::rtl::OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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< ::rtl::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< ::rtl::OUString >& aPropertyNames ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< ::rtl::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< ::rtl::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 ::rtl::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< ::rtl::OUString >& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + }; +} +#endif + diff --git a/comphelper/inc/comphelper/MasterPropertySetInfo.hxx b/comphelper/inc/comphelper/MasterPropertySetInfo.hxx new file mode 100644 index 000000000000..94a639fca755 --- /dev/null +++ b/comphelper/inc/comphelper/MasterPropertySetInfo.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * 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_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() + throw(); + 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(); + void remove( const rtl::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 ::rtl::OUString& aName ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) + throw(::com::sun::star::uno::RuntimeException); + }; +} +#endif diff --git a/comphelper/inc/comphelper/PropertyInfoHash.hxx b/comphelper/inc/comphelper/PropertyInfoHash.hxx new file mode 100644 index 000000000000..106f40487f5b --- /dev/null +++ b/comphelper/inc/comphelper/PropertyInfoHash.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * 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_PROPERTYINFOHASH_HXX_ +#define _COMPHELPER_PROPERTYINFOHASH_HXX_ + +#include <rtl/ustring.hxx> +#include <comphelper/TypeGeneration.hxx> +#include <hash_map> +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 rtl::OUString &r1, + const rtl::OUString &r2) const + { + return r1 == r2; + } + }; +} + +typedef std::hash_map < ::rtl::OUString, + ::comphelper::PropertyInfo*, + ::rtl::OUStringHash, + ::comphelper::eqFunc > PropertyInfoHash; +typedef std::hash_map < ::rtl::OUString, + ::comphelper::PropertyData*, + ::rtl::OUStringHash, + ::comphelper::eqFunc > PropertyDataHash; +#endif diff --git a/comphelper/inc/comphelper/SelectionMultiplex.hxx b/comphelper/inc/comphelper/SelectionMultiplex.hxx new file mode 100644 index 000000000000..633a86f4fdb8 --- /dev/null +++ b/comphelper/inc/comphelper/SelectionMultiplex.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * 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 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: + /** 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( 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 + diff --git a/comphelper/inc/comphelper/SettingsHelper.hxx b/comphelper/inc/comphelper/SettingsHelper.hxx new file mode 100644 index 000000000000..fa954009c78e --- /dev/null +++ b/comphelper/inc/comphelper/SettingsHelper.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * 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_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 vos +{ + class IMutex; +} + +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, ::vos::IMutex *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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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< ::rtl::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< ::rtl::OUString >& aPropertyNames ) + throw(::com::sun::star::uno::RuntimeException) + { return ComphelperBase::getPropertyValues ( aPropertyNames ); } + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< ::rtl::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< ::rtl::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 diff --git a/comphelper/inc/comphelper/TypeGeneration.hxx b/comphelper/inc/comphelper/TypeGeneration.hxx new file mode 100644 index 000000000000..6660e560f4af --- /dev/null +++ b/comphelper/inc/comphelper/TypeGeneration.hxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * 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_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_COLORMODE, //getCppuType( (drawing::ColorMode*)0 ) + CPPUTYPE_PAGESTYLELAY, //getCppuType( (style::PageStyleLayout*)0 ) + CPPUTYPE_VERTALIGN, //getCppuType( (style::VerticalAlignment*)0 ) + CPPUTYPE_TABLEBORDER, //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 ) + // --> OD 2004-08-09 #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 ) + + CPPUTYPE_END + }; + COMPHELPER_DLLPUBLIC void GenerateCppuType ( + CppuTypes eType, const com::sun::star::uno::Type*& pType ); +} +#endif diff --git a/comphelper/inc/comphelper/accessiblecomponenthelper.hxx b/comphelper/inc/comphelper/accessiblecomponenthelper.hxx new file mode 100644 index 000000000000..68fef8eb1f9e --- /dev/null +++ b/comphelper/inc/comphelper/accessiblecomponenthelper.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * 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_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 > + {}; + + /** 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 + + diff --git a/comphelper/inc/comphelper/accessiblecontexthelper.hxx b/comphelper/inc/comphelper/accessiblecontexthelper.hxx new file mode 100644 index 000000000000..32a83ca87219 --- /dev/null +++ b/comphelper/inc/comphelper/accessiblecontexthelper.hxx @@ -0,0 +1,376 @@ +/************************************************************************* + * + * 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_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 +{ +//......................................................................... + + class AccessibleEventBuffer; + + //===================================================================== + //= 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 IMutex + { + public: + 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 definately 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 + using WeakAggComponentImplHelperBase::addEventListener; + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + using WeakAggComponentImplHelperBase::removeEventListener; + virtual void SAL_CALL removeEventListener( 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 ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException) = 0; + virtual ::rtl::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 + ); + + /** records a certain event so that all AccessibleEventListeners can + be notified later on. + + Can even 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 + @param _rBuffer + the buffer that records the event + */ + virtual void SAL_CALL BufferAccessibleEvent( + const sal_Int16 _nEventId, + const ::com::sun::star::uno::Any& _rOldValue, + const ::com::sun::star::uno::Any& _rNewValue, + AccessibleEventBuffer & _rBuffer + ); + + // 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 + + diff --git a/comphelper/inc/comphelper/accessibleeventbuffer.hxx b/comphelper/inc/comphelper/accessibleeventbuffer.hxx new file mode 100644 index 000000000000..7f1107df50ad --- /dev/null +++ b/comphelper/inc/comphelper/accessibleeventbuffer.hxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#if !defined INCLUDED_COMPHELPER_ACCESSIBLEEVENTBUFFER_HXX +#define INCLUDED_COMPHELPER_ACCESSIBLEEVENTBUFFER_HXX + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" + +#include <vector> + +namespace com { namespace sun { namespace star { namespace uno { + class XInterface; +} } } } +namespace com { namespace sun { namespace star { + namespace accessibility { struct AccessibleEventObject; } +} } } + +namespace comphelper { + +/** + A buffer for AccessibleEventObjects about to be sent to + XAccessibleEventListeners. + + This buffer records pairs of AccessibleEventObjects and sequences of + XAccessibleEventListeners. At a time when it is safe to do so (e.g., when + no critical mutexes are held), all events can be notified at once. + + This class is not thread-safe in itself, but it is thread-compatible (i.e., + all multi-threaded uses of instances of this class have to ensure proper + mutual exclusion). + */ +class AccessibleEventBuffer +{ +public: + /** + Create an initially empty buffer. + + Internally uses ::std::vector and thus may throw exceptions thrown by + operations on ::std::vector, especially ::std::bad_alloc. + */ + AccessibleEventBuffer(); + + /** + Create a buffer with a copy of another buffer. + + The events from the other buffer are copied, not shared. + + Internally uses ::std::vector and thus may throw exceptions thrown by + operations on ::std::vector, especially ::std::bad_alloc. + */ + AccessibleEventBuffer(AccessibleEventBuffer const & rOther); + + /** + Destroy the buffer. + + If the buffer contains any events that have not yet been sent, those + events are lost. + + Does not throw any exceptions. + */ + ~AccessibleEventBuffer(); + + /** + Copy another buffer into this buffer. + + If this buffer contained any events that had not yet been sent, those + events are lost. The events from the other buffer are copied, not + shared. + + Internally uses ::std::vector and thus may throw exceptions thrown by + operations on ::std::vector, especially ::std::bad_alloc. + */ + AccessibleEventBuffer operator =(AccessibleEventBuffer const & rOther); + + /** + Add an event to the buffer. + + Internally uses ::std::vector and thus may throw exceptions thrown by + operations on ::std::vector, especially ::std::bad_alloc. + */ + void addEvent( + ::com::sun::star::accessibility::AccessibleEventObject const & + rEvent, + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > > const & rListeners); + + /** + Sends all the events accumulated in the buffer. + + If sending any of the events to a specific XAccessibleListener fails with + a RuntimeException, that exception is ignored and the method carries on + with the rest of the notifications. + + After sending all events, the buffer is cleared. + */ + void sendEvents() const; + +private: + struct Entry; + + typedef ::std::vector< Entry > Entries; + + Entries m_aEntries; +}; + +} + +#endif // INCLUDED_COMPHELPER_ACCESSIBLEEVENTBUFFER_HXX diff --git a/comphelper/inc/comphelper/accessibleeventnotifier.hxx b/comphelper/inc/comphelper/accessibleeventnotifier.hxx new file mode 100644 index 000000000000..7bf5ba76fa0c --- /dev/null +++ b/comphelper/inc/comphelper/accessibleeventnotifier.hxx @@ -0,0 +1,173 @@ +/************************************************************************* + * + * 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_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( ( ) ); + + /** retrieves the set of listeners registered for a given client + */ + static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > + getEventListeners( const TClientId _nClient ) 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 + + diff --git a/comphelper/inc/comphelper/accessiblekeybindinghelper.hxx b/comphelper/inc/comphelper/accessiblekeybindinghelper.hxx new file mode 100644 index 000000000000..4a7777727290 --- /dev/null +++ b/comphelper/inc/comphelper/accessiblekeybindinghelper.hxx @@ -0,0 +1,83 @@ +/************************************************************************* + * + * 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_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> + +#ifndef INCLUDED_VECTOR +#include <vector> +#define INCLUDED_VECTOR +#endif +#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 diff --git a/comphelper/inc/comphelper/accessibleselectionhelper.hxx b/comphelper/inc/comphelper/accessibleselectionhelper.hxx new file mode 100644 index 000000000000..12c31b39046c --- /dev/null +++ b/comphelper/inc/comphelper/accessibleselectionhelper.hxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * 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_ACCESSIBLE_SELECTION_HELPER_HXX +#define COMPHELPER_ACCESSIBLE_SELECTION_HELPER_HXX + +#include <comphelper/uno3.hxx> +#ifndef COMPHELPER_ACCESSIBLE_CONTEXT_HELPER_HXX +#include <comphelper/accessiblecomponenthelper.hxx> +#endif +#include <cppuhelper/implbase1.hxx> +#include <comphelper/uno3.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(); + + 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: + + OAccessibleSelectionHelper( ); + + /// 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 + diff --git a/comphelper/inc/comphelper/accessibletexthelper.hxx b/comphelper/inc/comphelper/accessibletexthelper.hxx new file mode 100644 index 000000000000..85ad893fd4c4 --- /dev/null +++ b/comphelper/inc/comphelper/accessibletexthelper.hxx @@ -0,0 +1,185 @@ +/************************************************************************* + * + * 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_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 ::rtl::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); + ::rtl::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); + ::rtl::OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException); + ::rtl::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 rtl::OUString& rOldString, + const rtl::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: + OAccessibleTextHelper(); + // 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 ::rtl::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 ::rtl::OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::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 +// +// ----------------------------------------------------------------------------- diff --git a/comphelper/inc/comphelper/accessiblewrapper.hxx b/comphelper/inc/comphelper/accessiblewrapper.hxx new file mode 100644 index 000000000000..3157142e990f --- /dev/null +++ b/comphelper/inc/comphelper/accessiblewrapper.hxx @@ -0,0 +1,411 @@ +/************************************************************************* + * + * 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_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 > + {}; + + /** 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 _rxORB + 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::lang::XMultiServiceFactory >& _rxORB, + 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 _rxORB + 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::lang::XMultiServiceFactory >& _rxORB, + ::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::WeakComponentImplHelper2< ::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 _rxORB + 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::lang::XMultiServiceFactory >& _rxORB, + 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 ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::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 + using WeakComponentImplHelperBase::addEventListener; + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + using WeakComponentImplHelperBase::removeEventListener; + virtual void SAL_CALL removeEventListener( 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/OComponentProxyAggregationHelper + virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); + + // 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::lang::XMultiServiceFactory > + m_xORB; + ::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::lang::XMultiServiceFactory >& _rxORB + ); + + /** 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 diff --git a/comphelper/inc/comphelper/accimplaccess.hxx b/comphelper/inc/comphelper/accimplaccess.hxx new file mode 100644 index 000000000000..8c0052ceae61 --- /dev/null +++ b/comphelper/inc/comphelper/accimplaccess.hxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * 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_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 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 successfull. 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 + ); + + /** sets or resets a state bit in the set of foreign-controlled states of the component. + + @param _rxComponent + is the component which's state is to be (re)set + @param _nState + the state bit which should be affected. This should be one of the respective UNO constants. + @param _bSet + <TRUE/> if the bit should be set, <FALSE/> otherwise + @return + <TRUE/> in case of success, <FALSE/> otherwise. For error condition please look at + <method>getImplementation</method>. + */ + static sal_Bool setForeignControlledState( + const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxComponent, + const sal_Int16 _nState, + const sal_Bool _bSet + ); + + + private: + COMPHELPER_DLLPRIVATE static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelImplementationId(); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + + +#endif // COMPHELPER_ACCIMPLACCESS_HXX + + diff --git a/comphelper/inc/comphelper/anytostring.hxx b/comphelper/inc/comphelper/anytostring.hxx new file mode 100644 index 000000000000..92c1685fb440 --- /dev/null +++ b/comphelper/inc/comphelper/anytostring.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#if ! defined(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 ::rtl::OUString anyToString( ::com::sun::star::uno::Any const & value ); + +} + +#endif + diff --git a/comphelper/inc/comphelper/asyncnotification.hxx b/comphelper/inc/comphelper/asyncnotification.hxx new file mode 100644 index 000000000000..fc4dfcd48dd9 --- /dev/null +++ b/comphelper/inc/comphelper/asyncnotification.hxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * 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_ASYNCNOTIFICATION_HXX +#define COMPHELPER_ASYNCNOTIFICATION_HXX + +#include <osl/thread.hxx> +#include <rtl/ref.hxx> +#include <comphelper/comphelperdllapi.h> +#include <rtl/alloc.h> + +#include <memory> + +//........................................................................ +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; + }; + + //==================================================================== + //= AsyncEventNotifier + //==================================================================== + typedef ::osl::Thread AsyncEventNotifier_TBASE; + 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 :protected AsyncEventNotifier_TBASE + ,public ::rtl::IReference + { + friend struct EventNotifierImpl; + + private: + ::std::auto_ptr< EventNotifierImpl > m_pImpl; + + protected: + // Thread + virtual void SAL_CALL run(); + virtual void SAL_CALL onTerminated(); + + public: + /** constructs a notifier thread + */ + AsyncEventNotifier(); + + // IReference implementations + virtual oslInterlockedCount SAL_CALL acquire(); + virtual oslInterlockedCount SAL_CALL release(); + + /// creates (starts) the thread + using AsyncEventNotifier_TBASE::create; + + using AsyncEventNotifier_TBASE::operator new; + using AsyncEventNotifier_TBASE::operator delete; + + /** 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 ); + + protected: + virtual ~AsyncEventNotifier(); + }; + + //==================================================================== + //= 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 diff --git a/comphelper/inc/comphelper/attributelist.hxx b/comphelper/inc/comphelper/attributelist.hxx new file mode 100644 index 000000000000..f408f6496fb9 --- /dev/null +++ b/comphelper/inc/comphelper/attributelist.hxx @@ -0,0 +1,77 @@ +/************************************************************************* + * + * 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_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 ::rtl::OUString &sName , const ::rtl::OUString &sType , const ::rtl::OUString &sValue ); + void Clear(); + void RemoveAttribute( const ::rtl::OUString sName ); + void SetAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & ); + void AppendAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & ); + + // ::com::sun::star::xml::sax::XAttributeList + virtual sal_Int16 SAL_CALL getLength(void) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::rtl::OUString SAL_CALL getNameByIndex(sal_Int16 i) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::rtl::OUString SAL_CALL getTypeByIndex(sal_Int16 i) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::rtl::OUString SAL_CALL getTypeByName(const ::rtl::OUString& aName) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::rtl::OUString SAL_CALL getValueByIndex(sal_Int16 i) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::rtl::OUString SAL_CALL getValueByName(const ::rtl::OUString& aName) + throw( ::com::sun::star::uno::RuntimeException ); + +}; + +} // namespace comphelper + +#endif // _COMPHELPER_ATTRIBUTE_LIST_HXX + diff --git a/comphelper/inc/comphelper/basicio.hxx b/comphelper/inc/comphelper/basicio.hxx new file mode 100644 index 000000000000..13ec58954d7d --- /dev/null +++ b/comphelper/inc/comphelper/basicio.hxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * 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_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); + +// ::rtl::OUString +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, ::rtl::OUString& _rStr); +COMPHELPER_DLLPUBLIC const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const ::rtl::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_ + diff --git a/comphelper/inc/comphelper/broadcasthelper.hxx b/comphelper/inc/comphelper/broadcasthelper.hxx new file mode 100644 index 000000000000..9e3f4816238c --- /dev/null +++ b/comphelper/inc/comphelper/broadcasthelper.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * 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_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_ diff --git a/comphelper/inc/comphelper/classids.hxx b/comphelper/inc/comphelper/classids.hxx new file mode 100644 index 000000000000..fddd7c5ad8c1 --- /dev/null +++ b/comphelper/inc/comphelper/classids.hxx @@ -0,0 +1,574 @@ +/************************************************************************* + * + * 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_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SW_CLASSID BF_SO3_SW_CLASSID_50 + +/* + * StarWriter/Web + */ + +/* 4.0 */ + +#define SO3_SWWEB_CLASSID_40 \ + 0xf0caa840, 0x7821, 0x11d0, 0xa4, 0xa7, 0x0, \ + 0xa0, 0x24, 0x9d, 0x57, 0xb1 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SWWEB_CLASSID_60 \ + 0xA8BBA60C, 0x7C60, 0x4550, 0x91, 0xCE, 0x39, \ + 0xC3, 0x90, 0x3F, 0xAC, 0x5E + +/* aktuell */ + +#define SO3_SWWEB_CLASSID SO3_SWWEB_CLASSID_60 + +// #110743# +#define BF_SO3_SWWEB_CLASSID BF_SO3_SWWEB_CLASSID_50 + +/* + * Globaldokument + */ + +/* 4.0 */ + +#define SO3_SWGLOB_CLASSID_40 \ + 0x340ac970, 0xe30d, 0x11d0, 0xa5, 0x3f, 0x0, \ + 0xa0, 0x24, 0x9d, 0x57, 0xb1 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SWGLOB_CLASSID_60 \ + 0xB21A0A7C, 0xE403, 0x41FE, 0x95, 0x62, 0xBD, \ + 0x13, 0xEA, 0x6F, 0x15, 0xA0 +/* aktuell */ + +#define SO3_SWGLOB_CLASSID SO3_SWGLOB_CLASSID_60 + +// #110743# +#define BF_SO3_SWGLOB_CLASSID BF_SO3_SWGLOB_CLASSID_50 + +//--------------------------------------------------- + +/* + * StarCalc + */ + +/* 3.0 */ + +#define SO3_SC_CLASSID_30 \ + 0x3F543FA0L, 0xB6A6, 0x101B, 0x99, 0x61, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SC_CLASSID BF_SO3_SC_CLASSID_50 + +/**************************************************** +* StarImpress +****************************************************/ + +/* 3.0 */ + +#define SO3_SIMPRESS_CLASSID_30 \ + 0xAF10AAE0L, 0xB36D, 0x101B, 0x99, 0x61, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SIMPRESS_CLASSID BF_SO3_SIMPRESS_CLASSID_50 + +/**************************************************** +* StarDraw +****************************************************/ + +/* 5.0 */ + +#define SO3_SDRAW_CLASSID_50 \ + 0x2e8905a0L, 0x85bd, 0x11d1, 0x89, 0xd0, 0x0, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SDRAW_CLASSID BF_SO3_SDRAW_CLASSID_50 + +/**************************************************** +* StarChart +****************************************************/ + +/* 3.0 */ + +#define SO3_SCH_CLASSID_30 \ + 0xFB9C99E0L, 0x2C6D, 0x101C, 0x8E, 0x2C, 0x00, \ + 0x00, 0x1B, 0x4C, 0xC7, 0x11 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SCH_CLASSID BF_SO3_SCH_CLASSID_50 + +/**************************************************** +* StarImage +****************************************************/ + +/* 3.0 */ + +#define SO3_SIM_CLASSID_30 \ + 0xEA60C941L, 0x2C6C, 0x101C, 0x8E, 0x2C, 0x00, \ + 0x00, 0x1B, 0x4C, 0xC7, 0x11 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SIM_CLASSID_50 \ + 0x65c68d00L, 0x85de, 0x11d1, 0x89, 0xd0, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +/* aktuell */ + +#define SO3_SIM_CLASSID SO3_SIM_CLASSID_50 + +// #110743# +#define BF_SO3_SIM_CLASSID BF_SO3_SIM_CLASSID_50 + +/*************************************************** +* StarMath +***************************************************/ + +/* 3.0 */ + +#define SO3_SM_CLASSID_30 \ + 0xD4590460L, 0x35FD, 0x101C, 0xB1, 0x2A, 0x04, \ + 0x02, 0x1C, 0x00, 0x70, 0x02 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_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 + +// #110743# +#define BF_SO3_SM_CLASSID BF_SO3_SM_CLASSID_50 + +#define SO3_OUT_CLASSID \ + 0x970b1e82, 0xcf2d, 0x11cf, 0x89, 0xca, 0x00, \ + 0x80, 0x29, 0xe4, 0xb0, 0xb1 + +// #110743# +#define BF_SO3_OUT_CLASSID \ + 0x970b1e83, 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 + +// #110743# +#define BF_SO3_APPLET_CLASSID \ + 0x970b1e82, 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 + +// #110743# +#define BF_SO3_PLUGIN_CLASSID \ + 0x4caa7762, 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 + +// #110743# +#define BF_SO3_IFRAME_CLASSID \ + 0x1a8a6702, 0xde58, 0x11cf, \ + 0x89, 0xca, 0x0, 0x80, 0x29, 0xe4, 0xb0, 0xb2 + +#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 diff --git a/comphelper/inc/comphelper/comphelperdllapi.h b/comphelper/inc/comphelper/comphelperdllapi.h new file mode 100644 index 000000000000..d7bd80d8a16d --- /dev/null +++ b/comphelper/inc/comphelper/comphelperdllapi.h @@ -0,0 +1,14 @@ +#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 */ + diff --git a/comphelper/inc/comphelper/componentbase.hxx b/comphelper/inc/comphelper/componentbase.hxx new file mode 100644 index 000000000000..12d5fdb64355 --- /dev/null +++ b/comphelper/inc/comphelper/componentbase.hxx @@ -0,0 +1,161 @@ +/************************************************************************* + * 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_COMPONENTBASE_HXX +#define COMPHELPER_COMPONENTBASE_HXX + +#include "comphelper/comphelperdllapi.h" + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#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 ) + { + } + + /** 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 diff --git a/comphelper/inc/comphelper/componentcontext.hxx b/comphelper/inc/comphelper/componentcontext.hxx new file mode 100644 index 000000000000..c2f68aab96c0 --- /dev/null +++ b/comphelper/inc/comphelper/componentcontext.hxx @@ -0,0 +1,252 @@ +/************************************************************************* + * + * 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_COMPONENTCONTEXT_HXX +#define COMPHELPER_COMPONENTCONTEXT_HXX + +#include <comphelper/comphelperdllapi.h> + +/** === begin UNO includes === **/ +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +/** === end UNO includes === **/ + +//........................................................................ +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 ::rtl::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( ::rtl::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 ::rtl::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( ::rtl::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 occured during creating the component + @return + the newly created component. Is never <NULL/>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const ::rtl::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 occured 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( ::rtl::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 occured during creating the component + @return + the newly created component. Is never <NULL/>. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponentWithArguments( + const ::rtl::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 occured 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( ::rtl::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 ::rtl::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( ::rtl::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 ::rtl::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( ::rtl::OUString::createFromAscii( _pAsciiName ) ); + } + + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_COMPONENTCONTEXT_HXX + diff --git a/comphelper/inc/comphelper/componentfactory.hxx b/comphelper/inc/comphelper/componentfactory.hxx new file mode 100644 index 000000000000..c23fbbca80d1 --- /dev/null +++ b/comphelper/inc/comphelper/componentfactory.hxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * 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_COMPONENTFACTORY_HXX +#define _COMPHELPER_COMPONENTFACTORY_HXX +#include "comphelper/comphelperdllapi.h" + +#include <com/sun/star/lang/XSingleServiceFactory.hpp> + + +/** + * @Descr + * Utilities to get an instance of a component if a ProcessServiceFactory + * is not available like it is the case in "small tools" as the Setup. + */ +#include <com/sun/star/uno/Reference.h> + + +#ifdef UNX +// "libNAMExy.so" (__DLLEXTENSION == "xy.so") +#define LLCF_LIBNAME( name ) "lib" name __DLLEXTENSION +#else +// "NAMExy.dll" (__DLLEXTENSION == "xy") +#define LLCF_LIBNAME( name ) name __DLLEXTENSION ".dll" +#endif + + +namespace rtl { + class OUString; +} +namespace com { namespace sun { namespace star { + namespace uno { + class XInterface; + } + namespace lang { + class XSingleServiceFactory; + class XMultiServiceFactory; + } + namespace registry { + class XRegistryKey; + } +}}} + + +namespace comphelper +{ + +/** + * Get an instance of the component <code>rImplementationName</code> located + * in library <code>rLibraryName</code>. The instance must then be queried + * for the desired interface with a queryInterface call. + * The library name must be constructed with the macro + * <code>LLCF_LIBNAME( name )</code> if it is a library from the normal build + * process which includes build number and platform name. + * + * @example:C++ + * <listing> + + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + Reference< whatever::XYourComponent > xComp; + // library name, e.g. xyz603mi.dll or libxyz603.so + ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( "xyz" ) ) ); + ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.whatever.YourComponent" ) ); + Reference< Xinterface > xI = ::comphelper::getComponentInstance( aLibName, aImplName ); + if ( xI.is() ) + { + Any x = xI->queryInterface( ::getCppuType((const Reference< whatever::XYourComponent >*)0) ); + x >>= xComp; + } + if ( !xComp.is() ) + // you're lost + + * </listing> + */ +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + getComponentInstance( + const ::rtl::OUString & rLibraryName, + const ::rtl::OUString & rImplementationName + ); + + +::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > + loadLibComponentFactory( + const ::rtl::OUString & rLibraryName, + const ::rtl::OUString & rImplementationName, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > & xKey + ); + + +} // namespace comphelper + +#endif // _COMPHELPER_COMPONENTFACTORY_HXX diff --git a/comphelper/inc/comphelper/componentmodule.hxx b/comphelper/inc/comphelper/componentmodule.hxx new file mode 100644 index 000000000000..660a685d0fd3 --- /dev/null +++ b/comphelper/inc/comphelper/componentmodule.hxx @@ -0,0 +1,441 @@ +/************************************************************************* + * + * 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_INC_COMPHELPER_COMPONENTMODULE_HXX +#define COMPHELPER_INC_COMPHELPER_COMPONENTMODULE_HXX + +#include <comphelper/comphelperdllapi.h> +#include <comphelper/legacysingletonfactory.hxx> + +/** === begin UNO includes === **/ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/registry/XRegistryKey.hpp> +/** === end UNO includes === **/ + +#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, + ::rtl::OUString const& _rComponentName, + ::com::sun::star::uno::Sequence< ::rtl::OUString > const & _rServiceNames, + rtl_ModuleCount* _pModuleCounter + ) SAL_THROW(()); + + //========================================================================= + //= ComponentDescription + //========================================================================= + struct COMPHELPER_DLLPUBLIC ComponentDescription + { + /// the implementation name of the component + ::rtl::OUString sImplementationName; + /// the services supported by the component implementation + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupportedServices; + /** the name under which the component implementation should be registered as singleton, + or empty if the component does not implement a singleton. + */ + ::rtl::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 ::rtl::OUString& _rImplementationName, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rSupportedServices, + const ::rtl::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 ::rtl::OUString& _rImplementationName, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames, + ::cppu::ComponentFactoryFunc _pCreateFunction, + FactoryInstantiation _pFactoryFunction = ::cppu::createSingleComponentFactory ); + + /** registers a component given by <type>ComponentDescription</type> + */ + void registerImplementation( const ComponentDescription& _rComp ); + + /** write the registration information of all known components + + Writes the registration information of all components which are currently registered into the + specified registry. + + Usually used from within component_writeInfo. + + @param_rxServiceManager + the service manager + @param _rRootKey + the registry key under which the information will be stored + @return + <TRUE/> if the registration of all implementations was successfull, <FALSE/> otherwise + */ + sal_Bool writeComponentInfos( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager, + const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey >& _rRootKey); + + /** version of writeComponentInfos which directly takes the arguments you got in your component_writeInfo call + */ + sal_Bool writeComponentInfos( void* pServiceManager, void* pRegistryKey ); + + /** creates a Factory for the component with the given implementation name. + <p>Usually used from within component_getFactory.<p/> + @param _rxServiceManager + a pointer to an XMultiServiceFactory interface as got in component_getFactory + @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 ::rtl::OUString& _rImplementationName, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager + ); + + /** version of getComponentFactory which directly takes the arguments you got in your component_getFactory call + */ + void* getComponentFactory( + const sal_Char* _pImplementationName, void* _pServiceManager, void* _pRegistryKey + ); + + 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 ressources + */ + 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 ::rtl::OUString getImplementationName_static()</code><li/> + <li><code>static ::com::sun::star::uno::Sequence< ::rtl::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 ::rtl::OUString getImplementationName_static()</code><li/> + <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static()</code><li/> + <li><code>static ::rtl::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 + ) ); + } + + //========================================================================== + //= OLegacySingletonRegistration + //========================================================================== + template <class TYPE> + class OLegacySingletonRegistration + { + public: + OLegacySingletonRegistration( OModule& _rModule ); + }; + + //-------------------------------------------------------------------------- + template <class TYPE> + OLegacySingletonRegistration<TYPE>::OLegacySingletonRegistration( OModule& _rModule ) + { + _rModule.registerImplementation( ComponentDescription( + TYPE::getImplementationName_static(), + TYPE::getSupportedServiceNames_static(), + ::rtl::OUString(), + &TYPE::Create, + &::comphelper::createLegacySingletonFactory + ) ); + } + + //========================================================================== + //= helpers + //========================================================================== + + //========================================================================== + // declaring a OModule for a component library + +#define DECLARE_COMPONENT_MODULE( ModuleClass, ClientClass ) \ + /* -------------------------------------------------------------------- */ \ + class ModuleClass : public ::comphelper::OModule \ + { \ + friend struct CreateModuleClass; \ + typedef ::comphelper::OModule BaseClass; \ + \ + public: \ + static ModuleClass& getInstance(); \ + \ + private: \ + ModuleClass(); \ + }; \ + \ + /* -------------------------------------------------------------------- */ \ + class ClientClass : public ::comphelper::OModuleClient \ + { \ + private: \ + typedef ::comphelper::OModuleClient BaseClass; \ + \ + public: \ + ClientClass() : BaseClass( ModuleClass::getInstance() ) \ + { \ + } \ + }; \ + \ + /* -------------------------------------------------------------------- */ \ + template < class TYPE > \ + class OAutoRegistration : public ::comphelper::OAutoRegistration< TYPE > \ + { \ + private: \ + typedef ::comphelper::OAutoRegistration< TYPE > BaseClass; \ + \ + public: \ + OAutoRegistration() : BaseClass( ModuleClass::getInstance() ) \ + { \ + } \ + }; \ + /* -------------------------------------------------------------------- */ \ + template < class TYPE > \ + class OSingletonRegistration : public ::comphelper::OSingletonRegistration< TYPE > \ + { \ + private: \ + typedef ::comphelper::OSingletonRegistration< TYPE > BaseClass; \ + \ + public: \ + OSingletonRegistration() : BaseClass( ModuleClass::getInstance() ) \ + { \ + } \ + }; \ + /* -------------------------------------------------------------------- */ \ + template < class TYPE > \ + class OLegacySingletonRegistration : public ::comphelper::OLegacySingletonRegistration< TYPE > \ + { \ + private: \ + typedef ::comphelper::OLegacySingletonRegistration< TYPE > BaseClass; \ + \ + public: \ + OLegacySingletonRegistration() : BaseClass( ModuleClass::getInstance() ) \ + { \ + } \ + }; \ + + //========================================================================== + //= implementing a OModule for a component library + +#define IMPLEMENT_COMPONENT_MODULE( ModuleClass ) \ + struct CreateModuleClass \ + { \ + ModuleClass* operator()() \ + { \ + static ModuleClass* pModule = new ModuleClass; \ + return pModule; \ + } \ + }; \ + \ + ModuleClass::ModuleClass() \ + :BaseClass() \ + { \ + } \ + \ + ModuleClass& ModuleClass::getInstance() \ + { \ + return *rtl_Instance< ModuleClass, CreateModuleClass, ::osl::MutexGuard, ::osl::GetGlobalMutex >:: \ + create( CreateModuleClass(), ::osl::GetGlobalMutex() ); \ + } \ + + //========================================================================== + //= implementing the API of a component library (component_*) + +#define IMPLEMENT_COMPONENT_LIBRARY_API( module_class, initializer_function ) \ + extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL \ + component_getImplementationEnvironment( \ + const sal_Char **ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) \ + { \ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; \ + } \ + extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo( \ + void* pServiceManager, void* pRegistryKey ) \ + { \ + initializer_function(); \ + return module_class::getInstance().writeComponentInfos( pServiceManager, pRegistryKey ); \ + } \ + extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( \ + const sal_Char* pImplementationName, void* pServiceManager, void* pRegistryKey ) \ + { \ + initializer_function(); \ + return module_class::getInstance().getComponentFactory( pImplementationName, pServiceManager, pRegistryKey ); \ + } + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_INC_COMPHELPER_COMPONENTMODULE_HXX + diff --git a/comphelper/inc/comphelper/composedprops.hxx b/comphelper/inc/comphelper/composedprops.hxx new file mode 100644 index 000000000000..93dab60cde13 --- /dev/null +++ b/comphelper/inc/comphelper/composedprops.hxx @@ -0,0 +1,127 @@ +/************************************************************************* + * + * 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_COMPOSEDPROPS_HXX_ +#define _COMPHELPER_COMPOSEDPROPS_HXX_ + +#include <cppuhelper/implbase2.hxx> +#include <comphelper/types.hxx> +#include <comphelper/stl_types.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <osl/mutex.hxx> +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + //===================================================================== + //= IPropertySetComposerCallback + //===================================================================== + class IPropertySetComposerCallback + { + public: + /** determines whether or not a property should appear in the composed property set + @param _rPropertyName + the name of the property + */ + virtual sal_Bool isComposeable(const ::rtl::OUString& _rPropertyName) const = 0; + }; + + //===================================================================== + //= OComposedPropertySet + //===================================================================== + class OComposedPropertySetInfo; + typedef ::cppu::WeakImplHelper2 < ::com::sun::star::beans::XPropertySet + , ::com::sun::star::beans::XPropertyState + > OComposedPropertySet_Base; + /** helper class for composing a property set from a sequence of other property sets. + <p>First: This class is a fast shot, so don't sue me :) (To be honest, it's the migration of an old ugly + implementation. It's still ugly).</p> + <p>The property listener mechanisms are not supported (you can't add property listeners).</p> + <p>Speaking strictly, the property defaults (getPropertyDefault) do not work correctly, as there's always + an empty <type scope="com.sun.star.uno">Any</type> returned.</p> + */ + class COMPHELPER_DLLPUBLIC OComposedPropertySet : public OComposedPropertySet_Base + { + private: + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > + m_aProperties; + OComposedPropertySetInfo* m_pInfo; + + protected: + ::osl::Mutex m_aMutex; + DECLARE_STL_VECTOR(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>, PropertySetArray); + PropertySetArray m_aSingleSets; + + public: + /** constructs a composed property set + + @param _rElements + the single property sets to compose + <p>The first property set in the sequence is the master set, any properties not present here + are not present in the composed set.<br/> + This may change in the future (as it's just missing implementation), so don't rely on this behaviour.</p> + + @param _pPropertyMetaData + the callback for retrieving property meta data (namely composeability)<br/> + if not specified, all properties are assumed to be composable + */ + OComposedPropertySet( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > & _rElements, + const IPropertySetComposerCallback* _pPropertyMetaData = NULL + ); + + // XPropertyState + virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::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< ::rtl::OUString >& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + // 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 ::rtl::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 ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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); + + protected: + ~OComposedPropertySet(); + void compose(const IPropertySetComposerCallback* _pMetaData); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_COMPOSEDPROPS_HXX_ + + diff --git a/comphelper/inc/comphelper/configurationhelper.hxx b/comphelper/inc/comphelper/configurationhelper.hxx new file mode 100644 index 000000000000..52603cd78b06 --- /dev/null +++ b/comphelper/inc/comphelper/configurationhelper.hxx @@ -0,0 +1,261 @@ +/************************************************************************* + * + * 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_CONFIGURATIONHELPER_HXX_ +#define _COMPHELPER_CONFIGURATIONHELPER_HXX_ + +//_______________________________________________ +// includes + +#include <com/sun/star/uno/XInterface.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 + +// no panic .. this define will be reseted at the end of this file. +// BUT doing so it's neccessary to add all includes BEFORE this css-value +// will be defined :_) +#ifdef css +#error "Who use css? I need it as namespace alias." +#else +#define css ::com::sun::star +#endif + +namespace comphelper{ + +//_______________________________________________ +// definitions + +//----------------------------------------------- +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 xSMGR + * 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 usefull 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::lang::XMultiServiceFactory > xSMGR , + const ::rtl::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 ::rtl::OUString& sRelPath, + const ::rtl::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 ::rtl::OUString& sRelPath, + const ::rtl::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 ::rtl::OUString& sRelPathToSet, + const ::rtl::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 usefull 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::lang::XMultiServiceFactory > xSMGR , + const ::rtl::OUString& sPackage, + const ::rtl::OUString& sRelPath, + const ::rtl::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 usefull 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::lang::XMultiServiceFactory > xSMGR , + const ::rtl::OUString& sPackage, + const ::rtl::OUString& sRelPath, + const ::rtl::OUString& sKey , + const css::uno::Any& aValue , + sal_Int32 eMode ); +}; + +} // namespace comphelper + +#undef css // important! + +#endif // _COMPHELPER_CONFIGURATIONHELPER_HXX_ diff --git a/comphelper/inc/comphelper/container.hxx b/comphelper/inc/comphelper/container.hxx new file mode 100644 index 000000000000..d509cada5603 --- /dev/null +++ b/comphelper/inc/comphelper/container.hxx @@ -0,0 +1,85 @@ +/************************************************************************* + * + * 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_CONTAINER_HXX_ +#define _COMPHELPER_CONTAINER_HXX_ + +#include <vector> +#include "com/sun/star/uno/Reference.hxx" +#include "comphelper/comphelperdllapi.h" + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//======================================================================== +//= IndexAccessIterator +//======================================================================== +/** ein Iterator, der von einem XIndexAccess ausgehend alle Elemente durchiteriert (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; + // das aktuelle Objekt + ::std::vector<sal_Int32> m_arrChildIndizies; + // ich bewege mich eigentlich durch einen Baum, dummerweise haben dessen + // Elemente aber kein GetNextSibling, also muss ich mir merken, wo die Childs + // innerhalb ihres Parents sitzen (das ist sozusagen der Pfad von der Wurzel + // zu m_xCurrentObject + + ::rtl::OUString m_ustrProperty; + // der Name der gesuchten 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; } + // damit kann man bestimmte Elemente ausschliessen, die werden dann einfach + // uebergangen + // wenn hier sal_True zurueckkommt, wird dieses Element von Next zurueckgeliefert, man kann sich hier also auch + // gleich ein paar zusaetzliche Angaben zu dem Element holen (deswegen ist die Methode auch nicht 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_ + + diff --git a/comphelper/inc/comphelper/containermultiplexer.hxx b/comphelper/inc/comphelper/containermultiplexer.hxx new file mode 100644 index 000000000000..f623f3040cad --- /dev/null +++ b/comphelper/inc/comphelper/containermultiplexer.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * 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_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>Usefull 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 + void lock(); + void unlock(); + 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_ + diff --git a/comphelper/inc/comphelper/docpasswordhelper.hxx b/comphelper/inc/comphelper/docpasswordhelper.hxx new file mode 100644 index 000000000000..dbbb68372a07 --- /dev/null +++ b/comphelper/inc/comphelper/docpasswordhelper.hxx @@ -0,0 +1,320 @@ +/************************************************************************* + * + * 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_DOCPASSWORDHELPR_HXX +#define COMPHELPER_DOCPASSWORDHELPR_HXX + +#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 function 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. + + @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 + occured while password verification. The password request loop + will be aborted. + */ + virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword ) = 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 ::rtl::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 ::rtl::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 ::rtl::OUString& aString ); + + // ------------------------------------------------------------------------ + + /** 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 sequence of bytes in BigEndian form + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GetWordHashAsSequence( + const ::rtl::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 ::rtl::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 ::rtl::OUString& aString, + rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 ); + + // ------------------------------------------------------------------------ + + /** 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 ::rtl::OUString requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + const ::rtl::OUString& rMediaPassword, + const ::com::sun::star::uno::Reference< + ::com::sun::star::task::XInteractionHandler >& rxInteractHandler, + const ::rtl::OUString& rDocumentName, + DocPasswordRequestType eRequestType, + const ::std::vector< ::rtl::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 ::rtl::OUString requestAndVerifyDocPassword( + IDocPasswordVerifier& rVerifier, + MediaDescriptor& rMediaDesc, + DocPasswordRequestType eRequestType, + const ::std::vector< ::rtl::OUString >* pDefaultPasswords = 0 ); + + // ------------------------------------------------------------------------ + +private: + ~DocPasswordHelper(); +}; + +// ============================================================================ + +} // namespace comphelper + +#endif + diff --git a/comphelper/inc/comphelper/docpasswordrequest.hxx b/comphelper/inc/comphelper/docpasswordrequest.hxx new file mode 100755 index 000000000000..cf04d22c7a6d --- /dev/null +++ b/comphelper/inc/comphelper/docpasswordrequest.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * 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_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 { + +// ============================================================================ + +/** 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 AbortContinuation; +class PasswordContinuation; + +/** 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 ::rtl::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 isAbort() const; + sal_Bool isPassword() const; + + ::rtl::OUString getPassword() const; + + ::rtl::OUString getPasswordToModify() const; + sal_Bool getRecommendReadOnly() const; + +private: + 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; + + sal_Bool mbPasswordToModify; +}; + +// ============================================================================ + +} // namespace comphelper + +#endif + diff --git a/comphelper/inc/comphelper/documentconstants.hxx b/comphelper/inc/comphelper/documentconstants.hxx new file mode 100644 index 000000000000..b78150586e28 --- /dev/null +++ b/comphelper/inc/comphelper/documentconstants.hxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * 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_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 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_WRITER_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_WRITER_WEB ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_WRITER_WEB_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_WRITER_GLOBAL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_DRAW ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_DRAW_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_IMPRESS ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_CALC ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_CALC_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_CHART ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_CHART_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_MATH ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_MATH_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_BASE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 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 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_WRITER_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_DRAW_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) ) +#define MIMETYPE_VND_SUN_XML_CALC_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 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 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_DRAWING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_CHART ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_FORMULA ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_DATABASE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 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 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) +#define MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 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 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ODFVER_010_TEXT_ASCII ) ) +#define ODFVER_011_TEXT ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ODFVER_011_TEXT_ASCII ) ) +#define ODFVER_012_TEXT ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ODFVER_012_TEXT_ASCII ) ) +#endif + diff --git a/comphelper/inc/comphelper/documentinfo.hxx b/comphelper/inc/comphelper/documentinfo.hxx new file mode 100644 index 000000000000..c791b8d26aab --- /dev/null +++ b/comphelper/inc/comphelper/documentinfo.hxx @@ -0,0 +1,59 @@ +/************************************************************************* + * + * 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_DOCUMENTINFO_HXX +#define COMPHELPER_DOCUMENTINFO_HXX + +#include "comphelper/comphelperdllapi.h" + +/** === begin UNO includes === **/ +#include <com/sun/star/frame/XModel.hpp> +/** === end UNO includes === **/ + +//........................................................................ +namespace comphelper { +//........................................................................ + + //==================================================================== + //= DocumentInfo + //==================================================================== + class COMPHELPER_DLLPUBLIC DocumentInfo + { + public: + /** retrieves the UI title of the given document + */ + static ::rtl::OUString getDocumentTitle( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument ); + + private: + DocumentInfo(); // never implemented + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_DOCUMENTINFO_HXX diff --git a/comphelper/inc/comphelper/embeddedobjectcontainer.hxx b/comphelper/inc/comphelper/embeddedobjectcontainer.hxx new file mode 100644 index 000000000000..c1382557c52a --- /dev/null +++ b/comphelper/inc/comphelper/embeddedobjectcontainer.hxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * 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_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; + }; + +struct EmbedImpl; +class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer +{ + EmbedImpl* pImpl; + + ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > Get_Impl( const ::rtl::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 >&, ::rtl::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 ::rtl::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(); + + ::rtl::OUString CreateUniqueObjectName(); + + // get a list of object names that have been added so far + com::sun::star::uno::Sequence < ::rtl::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 ::rtl::OUString& ); + sal_Bool HasEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& ); + sal_Bool HasInstantiatedEmbeddedObject( const ::rtl::OUString& ); + + // get the object name of an object - this is the persist name if the object has persistence + ::rtl::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 ::rtl::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 >&, ::rtl::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 >&, ::rtl::OUString& ); + + // insert an embedded object into the container - objects persistant representation will be added to the storage + sal_Bool InsertEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::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 >&, ::rtl::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 >&, ::rtl::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 >&, ::rtl::OUString& ); + + // copy an embedded object into the storage + sal_Bool CopyEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::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 ::rtl::OUString& aOrigName,*/ ::rtl::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 >&, ::rtl::OUString& ); + + // remove an embedded object from the container and from the storage; if object can't be closed + sal_Bool RemoveEmbeddedObject( const ::rtl::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 ::rtl::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 >&, ::rtl::OUString* pMediaType=0 ); + + // get the stored graphical representation by the object name + com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetGraphicStream( const ::rtl::OUString& aName, ::rtl::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 ::rtl::OUString& rObjectName, const ::rtl::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 ::rtl::OUString& rObjectName, const rtl::OUString& rMediaType ); + + // remove a graphical representation for an object + sal_Bool RemoveGraphicStream( const ::rtl::OUString& rObjectName ); + + // copy the graphical representation from different container + sal_Bool TryToCopyGraphReplacement( EmbeddedObjectContainer& rSrc, + const ::rtl::OUString& aOrigName, + const ::rtl::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 >&, + ::rtl::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 occured, otherwise <TRUE/>. + */ + sal_Bool SetPersistentEntries(const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& _xStorage,bool _bClearModifedFlag = true); +}; + +} + +#endif + diff --git a/comphelper/inc/comphelper/enumhelper.hxx b/comphelper/inc/comphelper/enumhelper.hxx new file mode 100644 index 000000000000..7272d9e91d20 --- /dev/null +++ b/comphelper/inc/comphelper/enumhelper.hxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * 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_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< ::rtl::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< ::rtl::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_ + + + diff --git a/comphelper/inc/comphelper/eventattachermgr.hxx b/comphelper/inc/comphelper/eventattachermgr.hxx new file mode 100644 index 000000000000..cae67a71d4d0 --- /dev/null +++ b/comphelper/inc/comphelper/eventattachermgr.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * 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_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; +} +namespace lang { + class XMultiServiceFactory; +} +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::beans::XIntrospection > & rIntrospection, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) + throw( ::com::sun::star::uno::Exception ); + + +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager > +createEventAttacherManager( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) + throw( ::com::sun::star::uno::Exception ); + +} + +#endif // _COMPHELPER_EVENTATTACHERMGR_HXX_ + diff --git a/comphelper/inc/comphelper/evtlistenerhlp.hxx b/comphelper/inc/comphelper/evtlistenerhlp.hxx new file mode 100644 index 000000000000..422b44abe7a0 --- /dev/null +++ b/comphelper/inc/comphelper/evtlistenerhlp.hxx @@ -0,0 +1,56 @@ +/************************************************************************* + * + * 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_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 diff --git a/comphelper/inc/comphelper/evtmethodhelper.hxx b/comphelper/inc/comphelper/evtmethodhelper.hxx new file mode 100755 index 000000000000..8e34b0e00149 --- /dev/null +++ b/comphelper/inc/comphelper/evtmethodhelper.hxx @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: evtlistenerhlp.hxx,v $ + * $Revision$ + * + * 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_EVENTMEHODHELPER_HXX +#define COMPHELPER_EVENMETHODHELPER_HXX +#include <comphelper/sequence.hxx> +//........................................................................ +namespace comphelper +{ + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString> getEventMethodsForType(const ::com::sun::star::uno::Type& type); +//........................................................................ + +} // namespace comphelper +//........................................................................ +#endif // COMPHELPER_EVENTMEHODHELPER_HXX diff --git a/comphelper/inc/comphelper/extract.hxx b/comphelper/inc/comphelper/extract.hxx new file mode 100644 index 000000000000..b44391c17911 --- /dev/null +++ b/comphelper/inc/comphelper/extract.hxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * 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_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 diff --git a/comphelper/inc/comphelper/fileformat.h b/comphelper/inc/comphelper/fileformat.h new file mode 100644 index 000000000000..65f37a2551b7 --- /dev/null +++ b/comphelper/inc/comphelper/fileformat.h @@ -0,0 +1,41 @@ +/************************************************************************* + * + * 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_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 + diff --git a/comphelper/inc/comphelper/genericpropertyset.hxx b/comphelper/inc/comphelper/genericpropertyset.hxx new file mode 100644 index 000000000000..6364dea5f020 --- /dev/null +++ b/comphelper/inc/comphelper/genericpropertyset.hxx @@ -0,0 +1,41 @@ +/************************************************************************* + * + * 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_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_ + diff --git a/comphelper/inc/comphelper/guarding.hxx b/comphelper/inc/comphelper/guarding.hxx new file mode 100644 index 000000000000..66de00738601 --- /dev/null +++ b/comphelper/inc/comphelper/guarding.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * 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_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_ + diff --git a/comphelper/inc/comphelper/ihwrapnofilter.hxx b/comphelper/inc/comphelper/ihwrapnofilter.hxx new file mode 100644 index 000000000000..1765716acb66 --- /dev/null +++ b/comphelper/inc/comphelper/ihwrapnofilter.hxx @@ -0,0 +1,102 @@ +/************************************************************************* +* + * 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_INTERACTIONHANDLERWRAPPER_HXX_ +#define _COMPHELPER_INTERACTIONHANDLERWRAPPER_HXX_ + +#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 + +#ifndef _CPPUHELPER_IMPLBASE3_HXX_ +#include <cppuhelper/implbase3.hxx> +#endif +#ifndef INCLUDED_COMPHELPERDLLAPI_H +#include "comphelper/comphelperdllapi.h" +#endif + +namespace comphelper { + + class COMPHELPER_DLLPUBLIC OIHWrapNoFilterDialog : public ::cppu::WeakImplHelper3 + < ::com::sun::star::task::XInteractionHandler + , ::com::sun::star::lang::XInitialization + , ::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 ::rtl::OUString SAL_CALL impl_staticGetImplementationName(); + static ::com::sun::star::uno::Sequence< ::rtl::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 ); + + //____________________________________________________________________________________________________ + // 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 ::rtl::OUString SAL_CALL getImplementationName() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw ( ::com::sun::star::uno::RuntimeException ); + + }; +} +#endif diff --git a/comphelper/inc/comphelper/implbase_var.hxx b/comphelper/inc/comphelper/implbase_var.hxx new file mode 100644 index 000000000000..97d360f853a6 --- /dev/null +++ b/comphelper/inc/comphelper/implbase_var.hxx @@ -0,0 +1,403 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +/** 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: + + #if ! defined(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. +*/ + +#if ! defined(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 + +#if ! defined(COMPHELPER_IMPLBASE_MAX_CTOR_ARGS) +#define COMPHELPER_IMPLBASE_MAX_CTOR_ARGS 6 // default +#endif + +#if ! defined(_CPPUHELPER_IMPLBASE_EX_HXX_) +#include "cppuhelper/implbase_ex.hxx" +#endif +#if ! defined(INCLUDED_RTL_INSTANCE_HXX) +#include "rtl/instance.hxx" +#endif +#if ! defined(_CPPUHELPER_COMPBASE_EX_HXX_) +#include "cppuhelper/compbase_ex.hxx" +#endif + +#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 ); } +}; + +} // namespace comphelper + +// undef for multiple use/inclusion of this header: +#undef COMPHELPER_IMPLBASE_MAX_CTOR_ARGS +#undef COMPHELPER_IMPLBASE_INTERFACE_NUMBER + diff --git a/comphelper/inc/comphelper/implementationreference.hxx b/comphelper/inc/comphelper/implementationreference.hxx new file mode 100644 index 000000000000..806cdc86f129 --- /dev/null +++ b/comphelper/inc/comphelper/implementationreference.hxx @@ -0,0 +1,273 @@ +/************************************************************************* + * + * 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_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 explicitely + 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 diff --git a/comphelper/inc/comphelper/interaction.hxx b/comphelper/inc/comphelper/interaction.hxx new file mode 100644 index 000000000000..1ae1dda61ec4 --- /dev/null +++ b/comphelper/inc/comphelper/interaction.hxx @@ -0,0 +1,170 @@ +/************************************************************************* + * + * 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_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 occured + + 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 ::rtl::OUString& _rInitialPassword ) + :m_sPassword( _rInitialPassword ) + { + } + + // XInteractionPassword + virtual void SAL_CALL setPassword( const ::rtl::OUString& _Password ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getPassword( ) throw (::com::sun::star::uno::RuntimeException); + + private: + ::rtl::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); + /// clear all continuations + void clearContinuations(); + + // 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_ + + diff --git a/comphelper/inc/comphelper/legacysingletonfactory.hxx b/comphelper/inc/comphelper/legacysingletonfactory.hxx new file mode 100644 index 000000000000..7180a66403bb --- /dev/null +++ b/comphelper/inc/comphelper/legacysingletonfactory.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * 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_LEGACYSINGLETONFACTORY_HXX +#define COMPHELPER_LEGACYSINGLETONFACTORY_HXX + +#include "comphelper/comphelperdllapi.h" + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#include <cppuhelper/factory.hxx> + +//........................................................................ +namespace comphelper +{ +//........................................................................ + +/** creates a factory which can be used when implementing old-style singletons + + Before UNO having the component context concept, singletons were implemented by providing + a factory which return the very same component instance for every creation request. + + Nowadays, singletons are implemented by making them available at the component context, + as dedicated property. + + To bridge between both worlds - sometimes necessary to support legacy code, which instantiates + singletons at the global service manager, instead of obtaining the property at the + component context -, you can use the function below. I creates a single-component + factory, which behaves like the old factories did: Upon multiple creation requests, + it will always return the same instance. Additionally, the signature of the function + is the same as the signature of <code>::cppu::createSingleComponentFactory</code> + (which creates a "normal" component factory), so you can use both factory functions + in the same context. +*/ +::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > + COMPHELPER_DLLPUBLIC createLegacySingletonFactory( + ::cppu::ComponentFactoryFunc _componentFactoryFunc, + const ::rtl::OUString& _rImplementationName, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames, + rtl_ModuleCount* _pModCount = NULL + ); + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_LEGACYSINGLETONFACTORY_HXX diff --git a/comphelper/inc/comphelper/listenernotification.hxx b/comphelper/inc/comphelper/listenernotification.hxx new file mode 100644 index 000000000000..f4bf2f916859 --- /dev/null +++ b/comphelper/inc/comphelper/listenernotification.hxx @@ -0,0 +1,308 @@ +/************************************************************************* + * + * 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_INC_COMPHELPER_LISTENERNOTIFICATION_HXX +#define COMPHELPER_INC_COMPHELPER_LISTENERNOTIFICATION_HXX + +#include <cppuhelper/interfacecontainer.hxx> + +/** === begin UNO includes === **/ +#include <com/sun/star/lang/XEventListener.hpp> +/** === end UNO includes === **/ +#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 + */ + inline ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > + createIterator(); + + 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(); + } + + inline ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > OListenerContainer::createIterator() + { + ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pIterator( new ::cppu::OInterfaceIteratorHelper( m_aListeners ) ); + return pIterator; + } + + //==================================================================== + //= 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 + diff --git a/comphelper/inc/comphelper/locale.hxx b/comphelper/inc/comphelper/locale.hxx new file mode 100644 index 000000000000..3fd8a15aa163 --- /dev/null +++ b/comphelper/inc/comphelper/locale.hxx @@ -0,0 +1,443 @@ +/************************************************************************* + * + * 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_LOCALE_HXX_ +#define _COMPHELPER_LOCALE_HXX_ + +//_______________________________________________ +// includes + +#include <vector> +#include <rtl/ustring.hxx> +#include "comphelper/comphelperdllapi.h" + +//_______________________________________________ +// namespace + +namespace comphelper{ + +//_______________________________________________ +// definitions + +/** @short A Locale object represents a specific geographical, political, or cultural region. + + @descr This Locale class can be used to: + - provide the different parts of a Locale (Language, Country, Variant) + - converting it from/to ISO formated string values (like e.g. "en-US") + - provide some predefined (static) Locale objects + */ +class COMPHELPER_DLLPUBLIC Locale +{ + //------------------------------------------- + // const + + public: + + /** @short seperates LANGUAGE and COUNTRY part of an ISO formated Locale. */ + static const sal_Unicode SEPERATOR_LC; + + /** @short seperates COUNTRY and VARIANT part of an ISO formated Locale. */ + static const sal_Unicode SEPERATOR_CV; + + /** @short seperates COUNTRY and VARIANT part of an ISO formated Locale. + @descr Its true for some linux derivates only :-( */ + static const sal_Unicode SEPERATOR_CV_LINUX; + + /** @short some predefined Locale objects. */ + static const Locale EN_US(); + static const Locale EN(); + static const Locale DE_DE(); + static const Locale DE_CH(); + static const Locale DE_AT(); + static const Locale AR(); + static const Locale CA(); + static const Locale CS(); + static const Locale DA(); + static const Locale EL(); + static const Locale ES(); + static const Locale FI(); + static const Locale FR(); + static const Locale HE(); + static const Locale HI_IN(); + static const Locale HU(); + static const Locale IT(); + static const Locale JA(); + static const Locale KO(); + static const Locale NL(); + static const Locale PL(); + static const Locale PT(); + static const Locale PT_BR(); + static const Locale RU(); + static const Locale SK(); + static const Locale SL(); + static const Locale SV(); + static const Locale TH(); + static const Locale TR(); + static const Locale X_DEFAULT(); + static const Locale X_COMMENT(); + static const Locale X_TRANSLATE(); + static const Locale X_NOTRANSLATE(); + static const Locale ZH_CN(); + static const Locale ZH_TW(); + + //------------------------------------------- + // types + + public: + + /** @short will be throw during convertion, if a Locale cant be interpreted. */ + struct MalFormedLocaleException + { + public: + ::rtl::OUString Message; + + MalFormedLocaleException() + {} + + MalFormedLocaleException(const ::rtl::OUString& sMessage) + : Message(sMessage) + {} + }; + + //------------------------------------------- + // member + + private : + + //--------------------------------------- + /** @short must be a valid ISO Language Code. + + @descr These codes are the lower-case two-letter codes as defined by ISO-639. + You can find a full list of these codes at a number of sites, such as: + <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> + http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a> + */ + ::rtl::OUString m_sLanguage; + + //--------------------------------------- + /** @short must be a valid ISO Country Code. + @descr These codes are the upper-case two-letter codes as defined by ISO-3166. + You can find a full list of these codes at a number of sites, such as: + <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html"> + http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a> + */ + ::rtl::OUString m_sCountry; + + //--------------------------------------- + /** @short Variant codes are vendor and browser-specific. + @descr For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. + Where there are two variants, separate them with an underscore, and + put the most important one first. For example, a Traditional Spanish collation + might be referenced, with "ES", "ES", "Traditional_WIN". + */ + ::rtl::OUString m_sVariant; + + //------------------------------------------- + // interface + + public : + + //--------------------------------------- + /** @short needed by outside users! + + @descr Otherwise it wouldnt be possible to use + any instance of such Locale static ... + */ + Locale(); + + //--------------------------------------- + /** @short construct a Locale from an ISO formated string value. + + @seealso fromISO() + + @param sISO + an ISO formated string value, which can be parsed and + tokenized into a Lamnguage, Country and Variant part. + + @throw MalFormedLocaleException + if conversion failed. + */ + Locale(const ::rtl::OUString& sISO) + throw(MalFormedLocaleException); + + //--------------------------------------- + /** @short construct a Locale from language, country and variant. + + @seealso setLanguage() + @seealso setCountry() + @seealso setVariant() + + @param sLanguage + lowercase two-letter ISO-639 code. + + @param sCountry + uppercase two-letter ISO-3166 code. + + @param sVariant + vendor and browser specific code. + */ + Locale(const ::rtl::OUString& sLanguage , + const ::rtl::OUString& sCountry , + const ::rtl::OUString& sVariant = ::rtl::OUString()); + + //--------------------------------------- + /** @short copy constructor. + + @param aCopy + the copy object. + */ + Locale(const Locale& aCopy); + + //--------------------------------------- + /** @short returns the language code for this locale. + + @descr That will either be the empty string or + a lowercase ISO 639 code. + + @return [string] + the language code. + */ + ::rtl::OUString getLanguage() const; + + //--------------------------------------- + /** @short returns the country/region code for this locale. + + @descr That will either be the empty string or an + upercase ISO 3166 2-letter code. + + @return [string] + the country code. + */ + ::rtl::OUString getCountry() const; + + //--------------------------------------- + /** @short returns the variant code for this locale. + + @return [string] + the variant code. + */ + ::rtl::OUString getVariant() const; + + //--------------------------------------- + /** @short set the new language code for this locale. + + @descr That will either be the empty string or + a lowercase ISO 639 code. + + @param sLanguage + the language code. + */ + void setLanguage(const ::rtl::OUString& sLanguage); + + //--------------------------------------- + /** @short set the new country/region code for this locale. + + @descr That will either be the empty string or an + upercase ISO 3166 2-letter code. + + @param sCountry + the country code. + */ + void setCountry(const ::rtl::OUString& sCountry); + + //--------------------------------------- + /** @short set the new variant code for this locale. + + @param sVariant + the variant code. + */ + void setVariant(const ::rtl::OUString& sVariant); + + //--------------------------------------- + /** @short take over new Locale informations. + + @seealso Locale(const ::rtl::OUString& sISO) + + @param sISO + an ISO formated string value, which can be parsed and + tokenized into a Lamnguage, Country and Variant part. + e.g. "en-US" or "en-US_WIN" + + @throw MalFormedLocaleException + if conversion failed. + */ + void fromISO(const ::rtl::OUString& sISO) + throw(MalFormedLocaleException); + + //--------------------------------------- + /** @short converts this Locale to an ISO formated string value. + + @descr The different parts of this Locale will be assempled + e.g. to "en-US" or "en-US_WIN" + + @return [string] + the ISO formated string. + */ + ::rtl::OUString toISO() const; + + //--------------------------------------- + /** @short check, if two Locale objects are equals. + + @descr All parts of a Locale (means Language, Country and Variant) + will be checked. + + @param aComparable + the Locale object for compare. + + @return [boolean] + TRUE if both objects uses the same values for + Language, Country and Variant. + */ + sal_Bool equals(const Locale& aComparable) const; + + //--------------------------------------- + /** @short check, if two Locale objects + uses the same language. + + @descr The Country and Variant parts of a Locale + wont be checked here. + + @return [boolean] + TRUE if both objects uses the same + Language value. + */ + sal_Bool similar(const Locale& aComparable) const; + + //--------------------------------------- + /** @short search for an equal or at least for a similar + Locale in a list of possible ones. + + @descr First it searches for a Locale, which is equals + to the reference Locale. + (means: same Language, Country, Variant) + + If the reference Locale couldnt be located, it will + tried again - but we are checking for "similar" Locales then. + (means: same Language) + + If no similar Locale could be located, we search + for a Locale "en-US" inside the given Locale list. + + If "en-US" could not be located, we search for + a Locale "en" inside the given list. + + If no "same" nor any "similar" locale could be found, + we try "x-default" and "x-notranslate" explicitly. + Sometimes localized variables are optimized and doesnt use + localzation realy. E.g. in case the localized value is a fix + product name. + + If no locale match till now, we use any other existing + locale, which exists inside the set of given ones! + + @seealso equals() + @seealso similar() + + @param lISOList + the list of possible Locales + (as formated ISO strings). + + @param sReferenceISO + the reference Locale, which should be searched + if its equals or similar to any Locale inside + the provided Locale list. + + @return An iterator, which points to the found element + inside the given Locale list. + If no matching Locale could be found, it points + to the end of the list. + + @throw [MalFormedLocaleException] + if at least one ISO formated string couldnt + be converted to a valid Locale Object. + */ + static ::std::vector< ::rtl::OUString >::const_iterator getFallback(const ::std::vector< ::rtl::OUString >& lISOList , + const ::rtl::OUString& sReferenceISO) + throw(MalFormedLocaleException); + + //--------------------------------------- + /** @short search for the next possible fallback locale. + + @descr Instead of getFallback(vector<>, string) this method + uses the given locale and decide by using an algorithm + which locale can be the next possible one. + + Algorithm: + - if locale has country return language only + - if locale different "en-US" return "en-US" + - if locale "en-US" return "en" + + @param aLocale [in/out]! + the incoming value will be used to start + search for a possible fallback ... + and in case such fallback was found this parameter + will be used for return too. + + @return TRUE if the parameter aLocale contains a new fallback value; + FALSE otherwise. + */ + static sal_Bool getFallback(Locale& aLocale); + + //--------------------------------------- + /** @short assign elements of another locale + to this instance. + + @param rCopy + another locale object. + */ + void operator=(const Locale& rCopy); + + //--------------------------------------- + /** @short check if two Locale objects are equals. + + @seealso equals() + + @param aComparable + the Locale object for compare. + + @return [boolean] + TRUE if both objects uses the same values for + Language, Country and Variant. + */ + sal_Bool operator==(const Locale& aComparable) const; + + //--------------------------------------- + /** @short check if two Locale objects are different. + + @param aComparable + the Locale object for compare. + + @return [boolean] + TRUE if at least one part of such Locale + isnt the same. + */ + sal_Bool operator!=(const Locale& aComparable) const; +}; + +} // namespace salhelper + +#endif // _COMPHELPER_LOCALE_HXX_ diff --git a/comphelper/inc/comphelper/logging.hxx b/comphelper/inc/comphelper/logging.hxx new file mode 100644 index 000000000000..20f9302cc853 --- /dev/null +++ b/comphelper/inc/comphelper/logging.hxx @@ -0,0 +1,794 @@ +/************************************************************************* + * + * 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_LOGGING_HXX +#define COMPHELPER_LOGGING_HXX + +#include <comphelper/comphelperdllapi.h> + +/** === begin UNO includes === **/ +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/logging/XLogHandler.hpp> +#include <com/sun/star/logging/LogLevel.hpp> +/** === end UNO includes === **/ + +#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 ::rtl::OUString& convertLogArgToString( const ::rtl::OUString& _rValue ) + { + return _rValue; + } + + inline ::rtl::OUString convertLogArgToString( const sal_Char* _pAsciiValue ) + { + return ::rtl::OUString::createFromAscii( _pAsciiValue ); + } + + inline ::rtl::OUString convertLogArgToString( double _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } + inline ::rtl::OUString convertLogArgToString( float _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } + inline ::rtl::OUString convertLogArgToString( sal_Int64 _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } + inline ::rtl::OUString convertLogArgToString( sal_Int32 _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } + inline ::rtl::OUString convertLogArgToString( sal_Int16 _nValue ) { return ::rtl::OUString::valueOf( (sal_Int32)_nValue ); } + inline ::rtl::OUString convertLogArgToString( sal_Unicode _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } + inline ::rtl::OUString convertLogArgToString( sal_Bool _nValue ) { return ::rtl::OUString::valueOf( _nValue ); } + + } } // namespace log::convert + + //==================================================================== + //= EventLogger + //==================================================================== + class EventLogger_Impl; + typedef ::boost::optional< ::rtl::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 name. + + @param _rxContext + the component context to create services + @param _rLoggerName + the name of the logger to create. If empty, the office-wide default logger will be used. + */ + EventLogger( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const ::rtl::OUString& _rLoggerName = ::rtl::OUString() + ); + + /** 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: + /** returns the name of the logger + */ + const ::rtl::OUString& getName() const; + + /// returns the current log level threshold of the logger + sal_Int32 getLogLevel() const; + + /// sets a new log level threshold of the logger + void setLogLevel( const sal_Int32 _nLogLevel ) const; + + /// determines whether an event with the given level would be logged + bool isLoggable( const sal_Int32 _nLogLevel ) const; + + /** adds the given log handler to the logger's set of handlers. + + Note that normally, you would not use this method: The logger implementations + initialize themselves from the configuration, where usually, a default log handler + is specified. In this case, the logger will create and use this handler. + + @return + <TRUE/> if and only if the addition was successful (as far as this can be detected + from outside the <code>XLogger</code>'s implementation. + */ + bool addLogHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogHandler >& _rxLogHandler ); + + /** removes the given log handler from the logger's set of handlers. + + @return + <TRUE/> if and only if the addition was successful (as far as this can be detected + from outside the <code>XLogger</code>'s implementation. + */ + bool removeLogHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogHandler >& _rxLogHandler ); + + //---------------------------------------------------------------- + //- 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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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, ::rtl::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 ::rtl::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 _rResourceBundleBaseName + the base name of the resource bundle to use. Will be used + in conjunction with XResourceBundleLoader::loadResource. + @param _rLoggerName + the name of the logger to work with. If empty, the office-wide + default logger will be used. + + */ + ResourceBasedEventLogger( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, + const ::rtl::OUString& _rResourceBundleBaseName, + const ::rtl::OUString& _rLoggerName = ::rtl::OUString() + ); + + /** 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: + ::rtl::OUString impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID ) const; + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_LOGGING_HXX diff --git a/comphelper/inc/comphelper/make_shared_from_uno.hxx b/comphelper/inc/comphelper/make_shared_from_uno.hxx new file mode 100644 index 000000000000..3acd4ec13dfe --- /dev/null +++ b/comphelper/inc/comphelper/make_shared_from_uno.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#if ! defined(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) + diff --git a/comphelper/inc/comphelper/makesequence.hxx b/comphelper/inc/comphelper/makesequence.hxx new file mode 100644 index 000000000000..4273356bf9aa --- /dev/null +++ b/comphelper/inc/comphelper/makesequence.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#if ! defined(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; \ +} + +#if ! defined(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) + diff --git a/comphelper/inc/comphelper/mediadescriptor.hxx b/comphelper/inc/comphelper/mediadescriptor.hxx new file mode 100644 index 000000000000..7d2333045390 --- /dev/null +++ b/comphelper/inc/comphelper/mediadescriptor.hxx @@ -0,0 +1,340 @@ +/************************************************************************* + * + * 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_MEDIADESCRIPTOR_HXX_ +#define _COMPHELPER_MEDIADESCRIPTOR_HXX_ + +//_______________________________________________ +// includes + +#include <comphelper/sequenceashashmap.hxx> +#include <rtl/ustring.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace com { namespace sun { namespace star { namespace io { + class XInputStream; +} } } } + +//_______________________________________________ +// namespace + +namespace comphelper{ + +//_______________________________________________ +// definitions + +/** @short can be used to work with a <type scope="::com::sun::star::document">MediaDescriptor</type> + struct. + + @descr It wraps a ::std::hash_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 +{ + //------------------------------------------- + // const + 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 ::rtl::OUString& PROP_ABORTED(); + static const ::rtl::OUString& PROP_ASTEMPLATE(); + static const ::rtl::OUString& PROP_CHARACTERSET(); + static const ::rtl::OUString& PROP_COMPONENTDATA(); + static const ::rtl::OUString& PROP_DEEPDETECTION(); + static const ::rtl::OUString& PROP_DETECTSERVICE(); + static const ::rtl::OUString& PROP_DOCUMENTSERVICE(); + static const ::rtl::OUString& PROP_EXTENSION(); + static const ::rtl::OUString& PROP_FILENAME(); + static const ::rtl::OUString& PROP_FILTERNAME(); + static const ::rtl::OUString& PROP_FILTEROPTIONS(); + static const ::rtl::OUString& PROP_FORMAT(); + static const ::rtl::OUString& PROP_FRAME(); + static const ::rtl::OUString& PROP_FRAMENAME(); + static const ::rtl::OUString& PROP_HIDDEN(); + static const ::rtl::OUString& PROP_INPUTSTREAM(); + static const ::rtl::OUString& PROP_INTERACTIONHANDLER(); + static const ::rtl::OUString& PROP_JUMPMARK(); + static const ::rtl::OUString& PROP_MACROEXECUTIONMODE(); + static const ::rtl::OUString& PROP_MEDIATYPE(); + static const ::rtl::OUString& PROP_MINIMIZED(); + static const ::rtl::OUString& PROP_NOAUTOSAVE(); + static const ::rtl::OUString& PROP_OPENNEWVIEW(); + static const ::rtl::OUString& PROP_OUTPUTSTREAM(); + static const ::rtl::OUString& PROP_PASSWORD(); + static const ::rtl::OUString& PROP_PATTERN(); + static const ::rtl::OUString& PROP_POSSIZE(); + static const ::rtl::OUString& PROP_POSTDATA(); + static const ::rtl::OUString& PROP_POSTSTRING(); + static const ::rtl::OUString& PROP_PREVIEW(); + static const ::rtl::OUString& PROP_READONLY(); + static const ::rtl::OUString& PROP_REFERRER(); + static const ::rtl::OUString& PROP_SALVAGEDFILE(); + static const ::rtl::OUString& PROP_SILENT(); + static const ::rtl::OUString& PROP_STATUSINDICATOR(); + static const ::rtl::OUString& PROP_STREAM(); + static const ::rtl::OUString& PROP_STREAMFOROUTPUT(); + static const ::rtl::OUString& PROP_TEMPLATENAME(); + static const ::rtl::OUString& PROP_TEMPLATEREGIONNAME(); + static const ::rtl::OUString& PROP_TITLE(); + static const ::rtl::OUString& PROP_TYPENAME(); + static const ::rtl::OUString& PROP_UCBCONTENT(); + static const ::rtl::OUString& PROP_UPDATEDOCMODE(); + static const ::rtl::OUString& PROP_URL(); + static const ::rtl::OUString& PROP_VERSION(); + static const ::rtl::OUString& PROP_VIEWID(); + static const ::rtl::OUString& PROP_REPAIRPACKAGE(); + static const ::rtl::OUString& PROP_DOCUMENTTITLE(); + static const ::rtl::OUString& PROP_MODEL(); + static const ::rtl::OUString& PROP_VIEWONLY(); + static const ::rtl::OUString& PROP_DOCUMENTBASEURL(); + static const ::rtl::OUString& PROP_VIEWCONTROLLERNAME(); + + //------------------------------------------- + // interface + public: + /** Value type of the 'ComponentData' property. + */ + typedef ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > ComponentDataSequence; + + //--------------------------------------- + /** @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::Any& aSource); + MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource); + MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& 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 otherwhise. + */ + 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 otherwhise. + */ + 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 otherwhise. + */ + 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 ComponentDataSequence (see above). + + @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 ::rtl::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 ComponentDataSequence (see above). 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 ::rtl::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 ComponentDataSequence (see above). 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 ::rtl::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 ::rtl::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 ::rtl::OUString impl_normalizeURL(const ::rtl::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 otherwhise. + */ + COMPHELPER_DLLPRIVATE sal_Bool impl_addInputStream( sal_Bool bLockFile ); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_MEDIADESCRIPTOR_HXX_ diff --git a/comphelper/inc/comphelper/mimeconfighelper.hxx b/comphelper/inc/comphelper/mimeconfighelper.hxx new file mode 100644 index 000000000000..5e02d4761cb1 --- /dev/null +++ b/comphelper/inc/comphelper/mimeconfighelper.hxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * 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_MIMECONFIGHELPER_HXX_ +#define _COMPHELPER_MIMECONFIGHELPER_HXX_ + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XNameAccess.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::lang::XMultiServiceFactory > m_xFactory; + ::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; + +public: + + MimeConfigurationHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); + + + static ::rtl::OUString GetStringClassIDRepresentation( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID ); + + static ::com::sun::star::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation( const ::rtl::OUString& aClassID ); + + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + GetConfigurationByPath( const ::rtl::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(); + + + ::rtl::OUString GetDocServiceNameFromFilter( const ::rtl::OUString& aFilterName ); + + ::rtl::OUString GetDocServiceNameFromMediaType( const ::rtl::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 ::rtl::OUString& aVerbShortcut, + ::com::sun::star::embed::VerbDescriptor& aDescriptor ); + + ::rtl::OUString GetExplicitlyRegisteredObjClassID( const ::rtl::OUString& aMediaType ); + + + // retrieving object description from configuration + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByStringClassID( + const ::rtl::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 ::rtl::OUString& aMediaType ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByFilter( + const ::rtl::OUString& aFilterName ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > GetObjectPropsByDocumentName( + const ::rtl::OUString& aDocumentName ); + + // retrieving object factory from configuration + ::rtl::OUString GetFactoryNameByStringClassID( const ::rtl::OUString& aStringClassID ); + ::rtl::OUString GetFactoryNameByClassID( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID ); + ::rtl::OUString GetFactoryNameByDocumentName( const ::rtl::OUString& aDocName ); + ::rtl::OUString GetFactoryNameByMediaType( const ::rtl::OUString& aMediaType ); + + // typedetection related + ::rtl::OUString UpdateMediaDescriptorWithFilterName( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, + sal_Bool bIgnoreType ); + ::rtl::OUString UpdateMediaDescriptorWithFilterName( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aObject ); + sal_Bool AddFilterNameCheckOwnFile( + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr ); + + ::rtl::OUString GetDefaultFilterFromServiceName( const ::rtl::OUString& aServName, sal_Int32 nVersion ); + + 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 ); + + ::com::sun::star::uno::Sequence<sal_Int8> GetSequenceClassIDFromObjectName(const ::rtl::OUString& _sObjectName) ; + +}; + +} + +#endif // _COMPHELPER_MIMECONFIGHELPER_HXX_ + diff --git a/comphelper/inc/comphelper/namecontainer.hxx b/comphelper/inc/comphelper/namecontainer.hxx new file mode 100644 index 000000000000..30d2326794b0 --- /dev/null +++ b/comphelper/inc/comphelper/namecontainer.hxx @@ -0,0 +1,42 @@ +/************************************************************************* + * + * 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_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_ + diff --git a/comphelper/inc/comphelper/namedvaluecollection.hxx b/comphelper/inc/comphelper/namedvaluecollection.hxx new file mode 100644 index 000000000000..72cd0e7cdfbe --- /dev/null +++ b/comphelper/inc/comphelper/namedvaluecollection.hxx @@ -0,0 +1,355 @@ +/************************************************************************* + * + * 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> + +/** === begin UNO includes === **/ +#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> +/** === end UNO includes === **/ + +#include <memory> +#include <algorithm> + +//........................................................................ +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::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 >() ); + } + + /// returns the number of elements in the collection + size_t size() const; + + /// determines whether the collection is empty + bool empty() 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( ::rtl::OUString::createFromAscii( _pAsciiValueName ), &_out_rValue, ::cppu::UnoType< VALUE_TYPE >::get() ); + } + + template < typename VALUE_TYPE > + bool get_ensureType( const ::rtl::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( ::rtl::OUString::createFromAscii( _pAsciiValueName ), _rDefault ); + } + + template < typename VALUE_TYPE > + VALUE_TYPE getOrDefault( const ::rtl::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( ::rtl::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 ::rtl::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( ::rtl::OUString::createFromAscii( _pAsciiValueName ) ); + } + + /// determines whether a value with a given name is present in the collection + inline bool has( const ::rtl::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( ::rtl::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 ::rtl::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( ::rtl::OUString::createFromAscii( _pAsciiValueName ), _rValue ); + } + + inline bool put( const ::rtl::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( ::rtl::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 ::rtl::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::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 ::rtl::OUString& _rValueName, + void* _pValueLocation, + const ::com::sun::star::uno::Type& _rExpectedValueType + ) const; + + const ::com::sun::star::uno::Any& + impl_get( const ::rtl::OUString& _rValueName ) const; + + bool impl_has( const ::rtl::OUString& _rValueName ) const; + + bool impl_put( const ::rtl::OUString& _rValueName, const ::com::sun::star::uno::Any& _rValue ); + + bool impl_remove( const ::rtl::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() ); + ::std::transform( + aValues.getConstArray(), + aValues.getConstArray() + aValues.getLength(), + aWrappedValues.getArray(), + ::com::sun::star::uno::makeAny< VALUE_TYPE > + ); + return aWrappedValues; + } + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // COMPHELPER_NAMEDVALUECOLLECTION_HXX + diff --git a/comphelper/inc/comphelper/numberedcollection.hxx b/comphelper/inc/comphelper/numberedcollection.hxx new file mode 100644 index 000000000000..03bc1e0b78ed --- /dev/null +++ b/comphelper/inc/comphelper/numberedcollection.hxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * 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_NUMBEREDCOLLECTION_HXX_ +#define _COMPHELPER_NUMBEREDCOLLECTION_HXX_ + +//_______________________________________________ +// includes + +#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 <hash_map> + +//_______________________________________________ +// namespace + +namespace comphelper{ + +#ifdef css + #error "Ambigious namespace definition of css." +#else + #define css ::com::sun::star +#endif + +//_______________________________________________ +// definitions + +/** @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 ::std::hash_map< + long , + TNumberedItem , + ::std::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 ::rtl::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 ::rtl::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 + ::rtl::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; +}; + +#undef css + +} // namespace comphelper + +#endif // _COMPHELPER_NUMBEREDCOLLECTION_HXX_ diff --git a/comphelper/inc/comphelper/numbers.hxx b/comphelper/inc/comphelper/numbers.hxx new file mode 100644 index 000000000000..ef5bbe73931c --- /dev/null +++ b/comphelper/inc/comphelper/numbers.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * 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_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 rtl::OUString& _rPropertyName + ); + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_NUMBERS_HXX_ + diff --git a/comphelper/inc/comphelper/officeresourcebundle.hxx b/comphelper/inc/comphelper/officeresourcebundle.hxx new file mode 100644 index 000000000000..d45209da9374 --- /dev/null +++ b/comphelper/inc/comphelper/officeresourcebundle.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * 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_OFFICE_RESOURCE_BUNDLE_HXX +#define COMPHELPER_OFFICE_RESOURCE_BUNDLE_HXX + +#include <comphelper/comphelperdllapi.h> + +/** === begin UNO includes === **/ +#include <com/sun/star/uno/XComponentContext.hpp> +/** === end UNO includes === **/ +#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 + @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 ::rtl::OUString& _bundleBaseName + ); + + /** 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. + */ + ::rtl::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 + diff --git a/comphelper/inc/comphelper/ofopxmlhelper.hxx b/comphelper/inc/comphelper/ofopxmlhelper.hxx new file mode 100644 index 000000000000..db203a08d750 --- /dev/null +++ b/comphelper/inc/comphelper/ofopxmlhelper.hxx @@ -0,0 +1,139 @@ +/************************************************************************* + * + * 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_OFOPXMLHELPER_HXX +#define _COMPHELPER_OFOPXMLHELPER_HXX + +#ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_ +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#endif +#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 + ::rtl::OUString m_aRelListElement; + ::rtl::OUString m_aRelElement; + ::rtl::OUString m_aIDAttr; + ::rtl::OUString m_aTypeAttr; + ::rtl::OUString m_aTargetModeAttr; + ::rtl::OUString m_aTargetAttr; + + // ContentType related strings + ::rtl::OUString m_aTypesElement; + ::rtl::OUString m_aDefaultElement; + ::rtl::OUString m_aOverrideElement; + ::rtl::OUString m_aExtensionAttr; + ::rtl::OUString m_aPartNameAttr; + ::rtl::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< ::rtl::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 ::rtl::OUString& aStringID, sal_uInt16 nFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory ) + 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 ::rtl::OUString aStreamName, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory ) + 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::lang::XMultiServiceFactory > xFactory ) + 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::lang::XMultiServiceFactory > xFactory ) + 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::lang::XMultiServiceFactory > xFactory ) + 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 ::rtl::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 ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::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 + diff --git a/comphelper/inc/comphelper/optional.hxx b/comphelper/inc/comphelper/optional.hxx new file mode 100644 index 000000000000..790e117622fd --- /dev/null +++ b/comphelper/inc/comphelper/optional.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#if ! defined(INCLUDED_COMPHELPER_OPTIONAL_HXX) +#define INCLUDED_COMPHELPER_OPTIONAL_HXX + +#if ! defined(_COM_SUN_STAR_BEANS_OPTIONAL_HPP_) +#include "com/sun/star/beans/Optional.hpp" +#endif +#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) + diff --git a/comphelper/inc/comphelper/optionalvalue.hxx b/comphelper/inc/comphelper/optionalvalue.hxx new file mode 100644 index 000000000000..f63e1cde51aa --- /dev/null +++ b/comphelper/inc/comphelper/optionalvalue.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * 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_OPTIONALVALUE_HXX +#define _COMPHELPER_OPTIONALVALUE_HXX + +#include <com/sun/star/uno/Any.hxx> + +namespace comphelper +{ + +/** @deprecated + Use boost/optional.hpp instead. +*/ + + + + /* Definition of OptionalValue template */ + + /** This template provides 'optionality' for the given value type. + + Especially for PODs, optionality either needs to be achieved + by special 'magic' values (i.e. an int value is not set when + -1 etc.), or an additional bool denoting value + validity. This template encapsulates the latter into an atomic + data type. + + @tpl Element + The value type that should be made optional + */ + template< typename Element > class OptionalValue + { + public: + typedef Element ValueType; + + /** Default-construct the value. + + A default-constructed value is not valid. You have to + explicitely set a value. + */ + OptionalValue() : + maValue(), + mbValid( false ) + { + } + + /** Construct the value. + + An explicitely constructed value is valid. To create an + invalid value, you have to default-construct it. + */ + OptionalValue( const Element& rValue ) : + maValue( rValue ), + mbValid( true ) + { + } + + // default copy/assignment operators are okay here + //OptionalValue(const OptionalValue&); + //OptionalValue& operator=( const OptionalValue& ); + + /** Query whether the value is valid + + @return true, if this object contains a valid value. + */ + bool isValid() const + { + return mbValid; + } + + /** Set a value. + + After this call, the object contains a valid value. + */ + void setValue( const Element& rValue ) + { + maValue = rValue; + mbValid = true; + } + + /** Get the value. + + The return value of this method is undefined, if the + object does not contain a valid value. + */ + Element getValue() const + { + return maValue; + } + + /** Clear the value. + + After this call, the object no longer contains a valid + value. + */ + void clearValue() + { + mbValid = false; + } + + // NOTE: The following two methods would optimally have been + // implemented as operator>>=/operator<<= + // overloads. Unfortunately, there's already a templatized + // version for those two methods, namely for UNO interface + // types. Adding a second would lead to ambiguities. + + /** Export the value into an Any. + + This method extracts the value into an Any. If the value + is invalid, the Any will be cleared. + + @return true, if the value has been successfully + transferred to the Any. Clearing the Any from an invalid + object is also considered a successful operation. + */ + bool exportValue( ::com::sun::star::uno::Any& o_rAny ) + { + o_rAny.clear(); + + if( isValid() ) + { + if( !(o_rAny <<= getValue()) ) + return false; + } + + return true; + } + + /** Import the value from an Any. + + This method imports the value from an Any. If the Any + is invalid, the object will get an invalid value. + + @return true, if the value has been successfully + transferred from the Any. Setting the value to invalid + from an empty Any is also considered a successful + operation. + */ + bool importValue( const ::com::sun::star::uno::Any& rAny ) + { + clearValue(); + + if( rAny.hasValue() ) + { + Element tmp; + + if( !(rAny >>= tmp) ) + return false; + + setValue( tmp ); + } + + return true; + } + + private: + Element maValue; + bool mbValid; + }; + +} + +#endif /* _COMPHELPER_OPTIONALVALUE_HXX */ diff --git a/comphelper/inc/comphelper/oslfile2streamwrap.hxx b/comphelper/inc/comphelper/oslfile2streamwrap.hxx new file mode 100644 index 000000000000..1a0a7cc55e04 --- /dev/null +++ b/comphelper/inc/comphelper/oslfile2streamwrap.hxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * 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 zum schreiben un lesen von Daten, basieren auf File +//================================================================== +struct InputStreamWrapper_Base : public ::cppu::WeakImplHelper1<stario::XInputStream> +{}; + +class COMPHELPER_DLLPUBLIC OSLInputStreamWrapper : public InputStreamWrapper_Base +{ + ::osl::Mutex m_aMutex; + ::osl::File* m_pFile; + sal_Bool m_bFileOwner : 1; + +public: + OSLInputStreamWrapper(::osl::File& _rStream); + OSLInputStreamWrapper(::osl::File* pStream, sal_Bool bOwner=sal_False); + virtual ~OSLInputStreamWrapper(); + +// UNO Anbindung + virtual void SAL_CALL acquire() throw() + { InputStreamWrapper_Base::acquire(); } + virtual void SAL_CALL release() throw() + { InputStreamWrapper_Base::release(); } + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException) + { return InputStreamWrapper_Base::queryInterface(_rType); } + +// 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, +// Datensenke fuer Files +//================================================================== +struct OutputStreamWrapper_Base : public ::cppu::WeakImplHelper1<stario::XOutputStream> +{}; + +class COMPHELPER_DLLPUBLIC OSLOutputStreamWrapper : public OutputStreamWrapper_Base +{ + ::osl::File& rFile; + +public: + OSLOutputStreamWrapper(::osl::File& _rFile) :rFile(_rFile) { } + +// UNO Anbindung + virtual void SAL_CALL acquire() throw() + { OutputStreamWrapper_Base::acquire(); } + virtual void SAL_CALL release() throw() + { OutputStreamWrapper_Base::release(); } + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException) + { return OutputStreamWrapper_Base::queryInterface(_rType); } + +// 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); +}; + +} // namespace comphelper + + +#endif // _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ + diff --git a/comphelper/inc/comphelper/otransactedfilestream.hxx b/comphelper/inc/comphelper/otransactedfilestream.hxx new file mode 100644 index 000000000000..b4533b5d9694 --- /dev/null +++ b/comphelper/inc/comphelper/otransactedfilestream.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * 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_OTRANSACTEDFILESTREAM_HXX +#define _COMPHELPER_OTRANSACTEDFILESTREAM_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 <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/mutex.hxx> +#include <cppuhelper/implbase7.hxx> +#include "comphelper/comphelperdllapi.h" + +namespace comphelper +{ + + +//================================================================== +// OTransactedFileStream +// allows to get transacted stream access to a file +// the file contents are automatically truncated, but the file +// itself is changed only on commit +// after the first commit the stream switches to direct mode +//================================================================== + +struct TTFileStreamData_Impl; +class COMPHELPER_DLLPUBLIC OTruncatedTransactedFileStream + : public ::cppu::WeakImplHelper7 < + ::com::sun::star::io::XStream, + ::com::sun::star::io::XInputStream, + ::com::sun::star::io::XOutputStream, + ::com::sun::star::io::XTruncate, + ::com::sun::star::io::XSeekable, + ::com::sun::star::beans::XPropertySetInfo, + ::com::sun::star::beans::XPropertySet > +{ + ::osl::Mutex m_aMutex; + TTFileStreamData_Impl* m_pStreamData; + + void CommonInit_Impl( + const ::rtl::OUString& aURL, + const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + sal_Bool bDeleteOptionIsProvided ); + + void CloseAll_Impl(); + +public: + + OTruncatedTransactedFileStream( const ::rtl::OUString& aURL, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); + + OTruncatedTransactedFileStream( const ::rtl::OUString& aURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); + + OTruncatedTransactedFileStream( const ::rtl::OUString& aURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, sal_Bool bDeleteIfNotCommited ); + + ~OTruncatedTransactedFileStream(); + + void Commit_Impl(); + void Revert_Impl(); + +// com::sun::star::io::XStream + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); + +// 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); + +// com::sun::star::io::XOutputStream + 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); + 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); + 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); + +// com::sun::star::io::XTruncate + virtual void SAL_CALL truncate( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + +// com::sun::star::io::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); + +// ::com::sun::star::beans::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 ::rtl::OUString& aName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException); + +// com::sun::star::beans::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 ::rtl::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 ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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); + +}; + +} // namespace comphelper + +#endif //_COMPHELPER_OTRANSACTEDFILESTREAM_HXX + + diff --git a/comphelper/inc/comphelper/processfactory.hxx b/comphelper/inc/comphelper/processfactory.hxx new file mode 100644 index 000000000000..aeaaf498c918 --- /dev/null +++ b/comphelper/inc/comphelper/processfactory.hxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * 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_PROCESSFACTORY_HXX_ +#define _COMPHELPER_PROCESSFACTORY_HXX_ + +#if ! defined(_COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HXX_) +#include "com/sun/star/uno/XComponentContext.hpp" +#endif +#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 get the process service factory. If no service factory is set the function returns + * a null interface. + * + * @author Juergen Schmidt + */ +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getProcessServiceFactory(); + +/** creates a component, using the process factory if set + @see getProcessServiceFactory + @see setProcessServiceFactory +*/ +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + createProcessComponent( + const ::rtl::OUString& _rServiceSpecifier + ) SAL_THROW( ( ::com::sun::star::uno::RuntimeException ) ); + +/** creates a component with arguments, using the process factory if set + + @see getProcessServiceFactory + @see setProcessServiceFactory +*/ +COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + createProcessComponentWithArguments( + const ::rtl::OUString& _rServiceSpecifier, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArgs + ) SAL_THROW( ( ::com::sun::star::uno::RuntimeException ) ); + +/** + * This function gets the process service factory's default component context. + * If no service factory is set the function returns a null interface. + */ +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_ + diff --git a/comphelper/inc/comphelper/propagg.hxx b/comphelper/inc/comphelper/propagg.hxx new file mode 100644 index 000000000000..b82f737d534b --- /dev/null +++ b/comphelper/inc/comphelper/propagg.hxx @@ -0,0 +1,329 @@ +/************************************************************************* + * + * 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_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; + sal_Bool bAggregate; + + OPropertyAccessor(sal_Int32 _nOriginalHandle, sal_Int32 _nPos, sal_Bool _bAggregate) + :nOriginalHandle(_nOriginalHandle) ,nPos(_nPos) ,bAggregate(_bAggregate) { } + OPropertyAccessor() + :nOriginalHandle(-1) ,nPos(-1) ,bAggregate(sal_False) { } + + sal_Bool operator==(const OPropertyAccessor& rOb) const { return nPos == rOb.nPos; } + sal_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 ::rtl::OUString& _rName) = 0; +}; + +/** + * 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( ::rtl::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 ::rtl::OUString& _rPropertyName) + throw(::com::sun::star::beans::UnknownPropertyException); + + /// inherited from IPropertyArrayHelper + virtual sal_Bool SAL_CALL hasPropertyByName(const ::rtl::OUString& _rPropertyName) ; + /// inherited from IPropertyArrayHelper + virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString & _rPropertyName); + /// inherited from IPropertyArrayHelper + virtual sal_Int32 SAL_CALL fillHandles( /*out*/sal_Int32* _pHandles, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rPropNames ); + + /** returns information about a property of the aggregate. + @param _pPropName points to a string to recieve the property name. No name is returned if this is NULL. + @param _pOriginalHandle points to a sal_Int32 to recieve 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 sal_Bool SAL_CALL fillAggregatePropertyInfoByHandle(::rtl::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 ::rtl::OUString& _rName ); + +protected: + const ::com::sun::star::beans::Property* findPropertyByName(const ::rtl::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 ::rtl::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 ::rtl::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< ::rtl::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< ::rtl::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 ::rtl::OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault(const ::rtl::OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault(const ::rtl::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; + ::rtl::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_ + diff --git a/comphelper/inc/comphelper/proparrhlp.hxx b/comphelper/inc/comphelper/proparrhlp.hxx new file mode 100644 index 000000000000..193f7e100c4a --- /dev/null +++ b/comphelper/inc/comphelper/proparrhlp.hxx @@ -0,0 +1,182 @@ +/************************************************************************* + * + * 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_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_ + + diff --git a/comphelper/inc/comphelper/property.hxx b/comphelper/inc/comphelper/property.hxx new file mode 100644 index 000000000000..5631cf5670f2 --- /dev/null +++ b/comphelper/inc/comphelper/property.hxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * 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_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 +*/ + struct PropertyStringLessFunctor : ::std::binary_function< ::com::sun::star::beans::Property, ::rtl::OUString, bool > + { + // ................................................................ + inline bool operator()( const ::com::sun::star::beans::Property& lhs, const ::rtl::OUString& rhs ) const + { + return lhs.Name.compareTo(rhs) < 0; + } + // ................................................................ + inline bool operator()( const ::rtl::OUString& lhs, const ::com::sun::star::beans::Property& rhs ) const + { + return lhs.compareTo(rhs.Name) < 0; + } + }; + //-------------------------------------------------------------------------- + // 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, ::rtl::OUString, bool > + { + // ................................................................ + inline bool operator()( const ::com::sun::star::beans::Property& lhs, const ::rtl::OUString& rhs ) const + { + return lhs.Name.compareTo(rhs) == 0; + } + // ................................................................ + inline bool operator()( const ::rtl::OUString& lhs, const ::com::sun::star::beans::Property& rhs ) const + { + return lhs.compareTo(rhs.Name) == 0; + } + }; + //-------------------------------------------------------------------------- + // 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.compareTo(y.Name) == 0; + } + }; + +//------------------------------------------------------------------ +/** find property with given name + + @param o_rProp + Output parameter receiving the property, if found + + @param i_rPropName + Name of the property to find + + @return false, if property was not found + */ +COMPHELPER_DLLPUBLIC bool findProperty(starbeans::Property& o_rProp, staruno::Sequence<starbeans::Property>& i_seqProps, const ::rtl::OUString& i_rPropName); + +//------------------------------------------------------------------ +/// remove the property with the given name from the given sequence +COMPHELPER_DLLPUBLIC void RemoveProperty(staruno::Sequence<starbeans::Property>& seqProps, const ::rtl::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 ::rtl::OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib); + +//------------------------------------------------------------------ +/** check if the given set has the given property. +*/ +COMPHELPER_DLLPUBLIC sal_Bool hasProperty(const rtl::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 successfull) + @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 TYPE> +sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, const TYPE& _rCurrentValue) +{ + sal_Bool bModified(sal_False); + TYPE aNewValue; + ::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 successfull) + @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 successfull) + @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; + ::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 successfull) + @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_ + diff --git a/comphelper/inc/comphelper/propertybag.hxx b/comphelper/inc/comphelper/propertybag.hxx new file mode 100644 index 000000000000..cf7e99768e44 --- /dev/null +++ b/comphelper/inc/comphelper/propertybag.hxx @@ -0,0 +1,237 @@ +/************************************************************************* + * + * 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_PROPERTYBAG_HXX +#define COMPHELPER_PROPERTYBAG_HXX + +#include "comphelper/comphelperdllapi.h" +#include <comphelper/propertycontainerhelper.hxx> + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +#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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 + diff --git a/comphelper/inc/comphelper/propertycontainer.hxx b/comphelper/inc/comphelper/propertycontainer.hxx new file mode 100644 index 000000000000..845ebd05e484 --- /dev/null +++ b/comphelper/inc/comphelper/propertycontainer.hxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * 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_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_ + + diff --git a/comphelper/inc/comphelper/propertycontainerhelper.hxx b/comphelper/inc/comphelper/propertycontainerhelper.hxx new file mode 100644 index 000000000000..82848203699c --- /dev/null +++ b/comphelper/inc/comphelper/propertycontainerhelper.hxx @@ -0,0 +1,218 @@ +/************************************************************************* + * + * 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_PROPERTYCONTAINERHELPER_HXX +#define COMPHELPER_PROPERTYCONTAINERHELPER_HXX + +#include <cppuhelper/propshlp.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/beans/Property.hpp> +#ifndef __SGI_STL_VECTOR +#include <vector> +#endif +#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( ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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; + + /** modify the attributes of an already registered property. + + You may want to use this if you're a derived from OPropertyContainer indirectly and want to override + some settings your base class did. + */ + void modifyAttributes(sal_Int32 _nHandle, sal_Int32 _nAddAttrib, sal_Int32 _nRemoveAttrib); + + /** 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 ::rtl::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 diff --git a/comphelper/inc/comphelper/propertysethelper.hxx b/comphelper/inc/comphelper/propertysethelper.hxx new file mode 100644 index 000000000000..505a03c1b4ec --- /dev/null +++ b/comphelper/inc/comphelper/propertysethelper.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * 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_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 ) = 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 ) = 0; + + virtual void _getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, ::com::sun::star::beans::PropertyState* pStates ) throw(::com::sun::star::beans::UnknownPropertyException ); + virtual void _setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry ) throw(::com::sun::star::beans::UnknownPropertyException ); + virtual ::com::sun::star::uno::Any _getPropertyDefault( const comphelper::PropertyMapEntry* pEntry ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ); + + // allow setting of properties after construction + void setInfo( comphelper::PropertySetInfo* pInfo ) throw(); + +public: + PropertySetHelper( ); + 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 ::rtl::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 ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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< ::rtl::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< ::rtl::OUString >& aPropertyNames ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener( const ::com::sun::star::uno::Sequence< ::rtl::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< ::rtl::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 ::rtl::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< ::rtl::OUString >& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); +}; + +//......................................................................... +} +//... namespace comphelper.................................................. + +#endif // _UTL_PROPERTYSETHELPER_HXX_ + diff --git a/comphelper/inc/comphelper/propertysetinfo.hxx b/comphelper/inc/comphelper/propertysetinfo.hxx new file mode 100644 index 000000000000..06ad4f4eecc3 --- /dev/null +++ b/comphelper/inc/comphelper/propertysetinfo.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * 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_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(); + + /** adds an array of PropertyMapEntry to this instance + + <p>At most the number of entries given will be added, if no terminating entry (<code>mpName == <NULL/></code>) is encountered.</p> + + <p>If <arg>nCount</arg> is less than 0, it is ignored and all entries (up to, but not including, the terminating + one) are added.</p> + */ + void add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw(); + + /** removes an already added PropertyMapEntry which string in mpName equals to aName */ + void remove( const rtl::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 ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException); +}; + +//......................................................................... +} +//... namespace comphelper ....................................................... + +#endif // _UTL_PROPERTSETINFO_HXX_ + diff --git a/comphelper/inc/comphelper/propertystatecontainer.hxx b/comphelper/inc/comphelper/propertystatecontainer.hxx new file mode 100644 index 000000000000..dde26ddf90cf --- /dev/null +++ b/comphelper/inc/comphelper/propertystatecontainer.hxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * 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_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 ::rtl::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< ::rtl::OUString >& aPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::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 ::rtl::OUString& _rPropertyName ) SAL_THROW( ( ::com::sun::star::beans::UnknownPropertyException ) ); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // COMPHELPER_PROPERTYSTATECONTAINER_HXX diff --git a/comphelper/inc/comphelper/propmultiplex.hxx b/comphelper/inc/comphelper/propmultiplex.hxx new file mode 100644 index 000000000000..4d640442a9ae --- /dev/null +++ b/comphelper/inc/comphelper/propmultiplex.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * 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_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< ::rtl::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 ::rtl::OUString& aPropertyName); + void dispose(); + }; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ + diff --git a/comphelper/inc/comphelper/propstate.hxx b/comphelper/inc/comphelper/propstate.hxx new file mode 100644 index 000000000000..b0c75147c95c --- /dev/null +++ b/comphelper/inc/comphelper/propstate.hxx @@ -0,0 +1,112 @@ +/************************************************************************* + * + * 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_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::OPropertySetHelper + ,public ::com::sun::star::beans::XPropertyState + { + public: + OPropertyStateHelper(::cppu::OBroadcastHelper& rBHlp):OPropertySetHelper(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 ::rtl::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< ::rtl::OUString >& aPropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL + setPropertyToDefault(const ::rtl::OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL + getPropertyDefault(const ::rtl::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_ + diff --git a/comphelper/inc/comphelper/proxyaggregation.hxx b/comphelper/inc/comphelper/proxyaggregation.hxx new file mode 100644 index 000000000000..c4c9281da8f2 --- /dev/null +++ b/comphelper/inc/comphelper/proxyaggregation.hxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * 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_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::lang::XMultiServiceFactory > m_xORB; + + protected: + inline const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getORB() + { + return m_xORB; + } + + protected: + OProxyAggregation( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB ); + ~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::getORB; + + // 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::lang::XMultiServiceFactory >& _rxORB, + ::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 + //========================================================================= + typedef ::cppu::WeakComponentImplHelperBase OComponentProxyAggregation_CBase; + + class COMPHELPER_DLLPUBLIC OComponentProxyAggregation :public OBaseMutex + ,public OComponentProxyAggregation_CBase + ,public OComponentProxyAggregationHelper + { + protected: + OComponentProxyAggregation( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + 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 diff --git a/comphelper/inc/comphelper/querydeep.hxx b/comphelper/inc/comphelper/querydeep.hxx new file mode 100644 index 000000000000..4115412d8d6c --- /dev/null +++ b/comphelper/inc/comphelper/querydeep.hxx @@ -0,0 +1,484 @@ +/************************************************************************* + * + * 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_QUERYDEEPINTERFACE_HXX +#define _COMPHELPER_QUERYDEEPINTERFACE_HXX + +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Type.hxx> + +/** */ //for docpp +namespace comphelper +{ + +//-------------------------------------------------------------------------------------------------------- +/** + * Inspect interfaces types whether they are related by inheritance. + *<BR> + * @return true if rType is derived from rBaseType + * @param rBaseType a <type>Type</type> of an interface. + * @param rType a <type>Type</type> of an interface. + */ +sal_Bool isDerivedFrom( + const ::com::sun::star::uno::Type & rBaseType, + const ::com::sun::star::uno::Type & rType ); + +//-------------------------------------------------------------------------------------------------------- +/** + * Inspect interface types whether they are related by inheritance. + *<BR> + * @return true if p is of a type derived from rBaseType + * @param rBaseType a <type>Type</type> of an interface. + * @param p a pointer to an interface. + */ +template <class Interface> +inline sal_Bool isDerivedFrom( + const ::com::sun::star::uno::Type& rBaseType, + Interface* /*p*/) +{ + return isDerivedFrom(rBaseType, Interface::static_type()); +} + +//-------------------------------------------------------------------------------------------------------- +// possible optimization ? +// Any aRet(::cppu::queryInterface(rType, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)); +// if (aRet.hasValue()) +// return aRet; + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + */ +template< class Interface1 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + */ +template< class Interface1, class Interface2 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, Interface7::static_type())) + return ::com::sun::star::uno::Any( &p7, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, Interface7::static_type())) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, Interface8::static_type())) + return ::com::sun::star::uno::Any( &p8, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, Interface7::static_type())) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, Interface8::static_type())) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, Interface9::static_type())) + return ::com::sun::star::uno::Any( &p9, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + * @param p10 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9, class Interface10 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9, Interface10 * p10 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, Interface7::static_type())) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, Interface8::static_type())) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, Interface9::static_type())) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, Interface10::static_type())) + return ::com::sun::star::uno::Any( &p10, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + * @param p10 a pointer to an interface. + * @param p11 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9, class Interface10, + class Interface11 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9, Interface10 * p10, + Interface11 * p11 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, Interface7::static_type())) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, Interface8::static_type())) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, Interface9::static_type())) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, Interface10::static_type())) + return ::com::sun::star::uno::Any( &p10, rType ); + else if (isDerivedFrom(rType, Interface11::static_type())) + return ::com::sun::star::uno::Any( &p11, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + * @param p10 a pointer to an interface. + * @param p11 a pointer to an interface. + * @param p12 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9, class Interface10, + class Interface11, class Interface12 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9, Interface10 * p10, + Interface11 * p11, Interface12 * p12 ) +{ + if (isDerivedFrom(rType, Interface1::static_type())) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, Interface2::static_type())) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, Interface3::static_type())) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, Interface4::static_type())) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, Interface5::static_type())) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, Interface6::static_type())) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, Interface7::static_type())) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, Interface8::static_type())) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, Interface9::static_type())) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, Interface10::static_type())) + return ::com::sun::star::uno::Any( &p10, rType ); + else if (isDerivedFrom(rType, Interface11::static_type())) + return ::com::sun::star::uno::Any( &p11, rType ); + else if (isDerivedFrom(rType, Interface12::static_type())) + return ::com::sun::star::uno::Any( &p12, rType ); + else + return ::com::sun::star::uno::Any(); +} + +} // namespace comphelper + +#endif // _COMPHELPER_QUERYDEEPINTERFACE_HXX + diff --git a/comphelper/inc/comphelper/regpathhelper.hxx b/comphelper/inc/comphelper/regpathhelper.hxx new file mode 100644 index 000000000000..431cdfb930a6 --- /dev/null +++ b/comphelper/inc/comphelper/regpathhelper.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * 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_REGPATHHELPER_HXX_ +#define _COMPHELPER_REGPATHHELPER_HXX_ + +#include <rtl/ustring.hxx> + +namespace comphelper +{ + +/** + * This function returns a path to the user registry file. + * Search for the user registry using the following rules: + * <dl> + * <dt> 1. (for further use) search in sversion.ini (.sversionrc) for an entry + * REGISTRY_VERSION_STRING (example: UserRegistry 5.0/505=test.rdb) in the section + * [Registry]. If found, then take this value instead of the name "user.rdb". + * <dt> 2. Search in the config directory of the user for a file "user.rdb". If + * found return the full path and name of the file. If not found, retry this + * step with a dot before ".user.rdb". + * <dt> 3. If not found a new user registry with name "user.rdb" will be created in the user + * config directory. + * </dl> + *<BR> + * @author Juergen Schmidt + */ +::rtl::OUString getPathToUserRegistry(); + +/** + * This function returns a path to the system registry file. + * The system registry will always be searched in the same directory of the + * executable. The name of the system registry is "applicat.rdb". If the system + * registry was not found, then the environment variable STAR_REGISTRY will be checked. + * If this variable was set, it must contain a full path to a valid system registry. + * Search for the user registry using the following rules: + * + *<BR> + * @author Juergen Schmidt + */ + +::rtl::OUString getPathToSystemRegistry(); + +} + +#endif + diff --git a/comphelper/inc/comphelper/scopeguard.hxx b/comphelper/inc/comphelper/scopeguard.hxx new file mode 100644 index 000000000000..4841a564ae61 --- /dev/null +++ b/comphelper/inc/comphelper/scopeguard.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#if ! defined(INCLUDED_COMPHELPER_SCOPEGUARD_HXX) +#define INCLUDED_COMPHELPER_SCOPEGUARD_HXX + +#if ! defined(INCLUDED_COMPHELPERDLLAPI_H) +#include "comphelper/comphelperdllapi.h" +#endif +#include "boost/function.hpp" +#include "boost/noncopyable.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) + diff --git a/comphelper/inc/comphelper/seekableinput.hxx b/comphelper/inc/comphelper/seekableinput.hxx new file mode 100644 index 000000000000..5fc7ab5b369f --- /dev/null +++ b/comphelper/inc/comphelper/seekableinput.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * 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_SEEKABLEINPUT_HXX_ +#define _COMPHELPER_STREAM_SEEKABLEINPUT_HXX_ + +#include <osl/mutex.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.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::lang::XMultiServiceFactory > m_xFactory; + + ::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::lang::XMultiServiceFactory >& xFactory ); + + 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::lang::XMultiServiceFactory >& xFactory ); + +// 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 + diff --git a/comphelper/inc/comphelper/seqstream.hxx b/comphelper/inc/comphelper/seqstream.hxx new file mode 100644 index 000000000000..dcde150953f6 --- /dev/null +++ b/comphelper/inc/comphelper/seqstream.hxx @@ -0,0 +1,146 @@ +/************************************************************************* + * + * 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_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 + + diff --git a/comphelper/inc/comphelper/sequence.hxx b/comphelper/inc/comphelper/sequence.hxx new file mode 100644 index 000000000000..5e9c5dc49040 --- /dev/null +++ b/comphelper/inc/comphelper/sequence.hxx @@ -0,0 +1,389 @@ +/************************************************************************* + * + * 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_SEQUENCE_HXX_ +#define _COMPHELPER_SEQUENCE_HXX_ + +#ifndef INCLUDED_ALGORITHM +#include <algorithm> // copy algorithm +#define INCLUDED_ALGORITHM +#endif +#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 occurence will be returned. + */ + COMPHELPER_DLLPUBLIC staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::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 ::rtl::OUString& Value,const ::com::sun::star::uno::Sequence< ::rtl::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 + //===================================================================== + class SAL_NO_VTABLE IIterator + { + public: + virtual sal_Bool hasMoreElements() const = 0; + virtual ::com::sun::star::uno::Any nextElement() = 0; + }; + /** a helper class for iterating through a sequence + */ + template <class TYPE> + class OSequenceIterator : public IIterator + { + 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); + + virtual sal_Bool hasMoreElements() const; + virtual ::com::sun::star::uno::Any nextElement(); + + protected: + 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; + #ifdef DBG_UTIL + sal_Bool bSuccess = + #endif + _rSequenceAny >>= aContainer; + #ifdef DBG_UTIL + OSL_ENSURE(bSuccess, "OSequenceIterator::OSequenceIterator: invalid Any!"); + #endif + 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_ + diff --git a/comphelper/inc/comphelper/sequenceashashmap.hxx b/comphelper/inc/comphelper/sequenceashashmap.hxx new file mode 100644 index 000000000000..737fd41efb84 --- /dev/null +++ b/comphelper/inc/comphelper/sequenceashashmap.hxx @@ -0,0 +1,384 @@ +/************************************************************************* + * + * 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_SEQUENCEASHASHMAP_HXX_ +#define _COMPHELPER_SEQUENCEASHASHMAP_HXX_ + +//_______________________________________________ +// includes + +#ifndef INCLUDED_HASH_MAP +#include <hash_map> +#define INCLUDED_HASH_MAP +#endif + +#ifndef INCLUDED_ALGORITHM +#include <algorithm> +#define INCLUDED_ALGORITHM +#endif +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> + +#ifndef _COM_SUN_STAR_BEANS_IllegalTypeException_HPP_ +#include <com/sun/star/beans/IllegalTypeException.hpp> +#endif +#include "comphelper/comphelperdllapi.h" + +// see method dbg_dumpToFile() below! +#if OSL_DEBUG_LEVEL > 1 + #ifndef _RTL_USTRBUF_HXX_ + #include <rtl/ustrbuf.hxx> + #endif + + #include <stdio.h> +#endif + +//_______________________________________________ +// namespace + +namespace comphelper{ + +//_______________________________________________ +// definitions + +/** @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 ::std::hash_map< + ::rtl::OUString , + ::com::sun::star::uno::Any , + ::rtl::OUStringHash , + ::std::equal_to< ::rtl::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 usefull :-) + */ + ~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 as a + sequence< 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 sequence which elements of Any, which + contains all items of this map. + */ + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > getAsConstAnyList(::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 otherwhise. + + @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 otherwhise. + + @attention "unpacked" means the Any content of every iterator->second! + */ + template< class TValueType > + TValueType getUnpackedValueOrDefault(const ::rtl::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 ::rtl::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); + + //--------------------------------------- + /** @short can be used to generate a file dump of + the current content of this instance. + + @descr Because the content of STL container + cant be analyzed easy, such dump function + seem to be usefull. + Of course its available in debug versions + only. + + @param pFileName + a system file name. + (doesnt matter if relativ or absolute) + + @param pComment + used to mark the dump inside the same log file. + Can be usefull to analyze changes of this + hash map due to the parts of an operation. + */ + #if OSL_DEBUG_LEVEL > 1 + void dbg_dumpToFile(const char* pFileName, const char* pComment) const; + #endif +}; + +} // namespace comphelper + +#endif // _COMPHELPER_SEQUENCEASHASHMAP_HXX_ diff --git a/comphelper/inc/comphelper/sequenceasvector.hxx b/comphelper/inc/comphelper/sequenceasvector.hxx new file mode 100644 index 000000000000..263b68b24c7c --- /dev/null +++ b/comphelper/inc/comphelper/sequenceasvector.hxx @@ -0,0 +1,247 @@ +/************************************************************************* + * + * 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_SEQUENCEASVECTOR_HXX_ +#define _COMPHELPER_SEQUENCEASVECTOR_HXX_ + +//_______________________________________________ +// includes + +#include <vector> +#include <algorithm> +#include <com/sun/star/uno/Sequence.hxx> + +#ifndef _COM_SUN_STAR_BEANS_IllegalTypeException_HPP_ +#include <com/sun/star/beans/IllegalTypeException.hpp> +#endif + +//_______________________________________________ +// namespace + +namespace comphelper{ + +//_______________________________________________ +// definitions + +/** @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 usefull 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; + + //------------------------------------------- + // interface + public: + + //--------------------------------------- + /** @short default ctor, to create an empty list. + */ + SequenceAsVector() + {} + + //--------------------------------------- + /** @short default dtor + */ + ~SequenceAsVector() + {} + + //--------------------------------------- + /** @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) + 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( + ::rtl::OUString::createFromAscii("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_ + diff --git a/comphelper/inc/comphelper/servicedecl.hxx b/comphelper/inc/comphelper/servicedecl.hxx new file mode 100644 index 000000000000..5d11d41831f5 --- /dev/null +++ b/comphelper/inc/comphelper/servicedecl.hxx @@ -0,0 +1,459 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#if ! defined(COMPHELPER_SERVICEDECL_HXX_INCLUDED) +#define COMPHELPER_SERVICEDECL_HXX_INCLUDED + +#if ! defined(INCLUDED_COMPHELPERDLLAPI_H) +#include "comphelper/comphelperdllapi.h" +#endif +#if ! defined(_CPPUHELPER_IMPLBASE1_HXX_) +#include "cppuhelper/implbase1.hxx" +#endif +#if ! defined(_COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_) +#include "com/sun/star/uno/XComponentContext.hpp" +#endif +#if ! defined(_COM_SUN_STAR_LANG_XSERVICEINFO_HPP_) +#include "com/sun/star/lang/XServiceInfo.hpp" +#endif +#if ! defined(_COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_) +#include "com/sun/star/registry/XRegistryKey.hpp" +#endif +#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 { +namespace css = ::com::sun::star; +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 : 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 : 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_writeInfoHelper() + bool writeInfo( ::com::sun::star::registry::XRegistryKey * xKey ) const; + /// @internal gets called by component_getFactoryHelper() + void * getFactory( sal_Char const* pImplName ) const; + + /// @return supported service names + ::com::sun::star::uno::Sequence< ::rtl::OUString> + getSupportedServiceNames() const; + + /// @return whether name is in set of supported service names + bool supportsService( ::rtl::OUString const& name ) const; + + /// @return implementation name + ::rtl::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 ::rtl::OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException) { + return m_rServiceDecl.getImplementationName(); + } + virtual sal_Bool SAL_CALL supportsService( ::rtl::OUString const& name ) + throw (css::uno::RuntimeException) { + return m_rServiceDecl.supportsService(name); + } + virtual css::uno::Sequence< ::rtl::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_writeInfo(z_, n_, unused_) \ + bRet &= BOOST_PP_CAT(s, n_).writeInfo( xRegistryKey ); + +#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 sal_Bool component_writeInfoHelper( + ::com::sun::star::lang::XMultiServiceFactory *, + ::com::sun::star::registry::XRegistryKey * xRegistryKey, + ServiceDecl const& s0, ServiceDecl const& s1, ... ); + + 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 sal_Bool component_writeInfoHelper( \ + ::com::sun::star::lang::XMultiServiceFactory *, \ + ::com::sun::star::registry::XRegistryKey * xRegistryKey, \ + BOOST_PP_ENUM_PARAMS(n_, ServiceDecl const& s) ) \ +{ \ + bool bRet = true; \ + BOOST_PP_REPEAT(n_, COMPHELPER_SERVICEDECL_writeInfo, ~) \ + return bRet; \ +} \ +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; \ +} + +#if ! defined(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 +#undef COMPHELPER_SERVICEDECL_writeInfo + +} // 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(varargs_ ) \ +extern "C" \ +{ \ + SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvTypeName, \ + uno_Environment** /*ppEnv*/ ) \ + { \ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; \ + } \ + \ + SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo( ::com::sun::star::lang::XMultiServiceFactory* pServiceManager, \ + ::com::sun::star::registry::XRegistryKey* pRegistryKey ) \ + { \ + return component_writeInfoHelper( pServiceManager, pRegistryKey, \ + BOOST_PP_SEQ_ENUM(varargs_) ); \ + } \ + \ + SAL_DLLPUBLIC_EXPORT void* SAL_CALL 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(comp0_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)) +#define COMPHELPER_SERVICEDECL_EXPORTS2(comp0_,comp1_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)) +#define COMPHELPER_SERVICEDECL_EXPORTS3(comp0_,comp1_,comp2_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)(comp2_)) +#define COMPHELPER_SERVICEDECL_EXPORTS4(comp0_,comp1_,comp2_,comp3_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)(comp2_)(comp3_)) +#define COMPHELPER_SERVICEDECL_EXPORTS5(comp0_,comp1_,comp2_,comp3_,comp4_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)(comp2_)(comp3_)(comp4_)) +#define COMPHELPER_SERVICEDECL_EXPORTS6(comp0_,comp1_,comp2_,comp3_,comp4_,comp5_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)(comp2_)(comp3_)(comp4_)(comp5_)) +#define COMPHELPER_SERVICEDECL_EXPORTS7(comp0_,comp1_,comp2_,comp3_,comp4_,comp5_,comp6_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)(comp2_)(comp3_)(comp4_)(comp5_)(comp6_)) +#define COMPHELPER_SERVICEDECL_EXPORTS8(comp0_,comp1_,comp2_,comp3_,comp4_,comp5_,comp6_,comp7_) \ + COMPHELPER_SERVICEDECL_make_exports((comp0_)(comp1_)(comp2_)(comp3_)(comp4_)(comp5_)(comp6_)(comp7_)) + +#endif // ! defined(COMPHELPER_SERVICEDECL_HXX_INCLUDED) + diff --git a/comphelper/inc/comphelper/servicehelper.hxx b/comphelper/inc/comphelper/servicehelper.hxx new file mode 100644 index 000000000000..e856ec9f64b5 --- /dev/null +++ b/comphelper/inc/comphelper/servicehelper.hxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * 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_SERVICEHELPER_HXX_ +#define _COMPHELPER_SERVICEHELPER_HXX_ + +/** 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 ) \ +const ::com::sun::star::uno::Sequence< sal_Int8 > & classname::getUnoTunnelId() throw() \ +{ \ + static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = 0; \ + if( !pSeq ) \ + { \ + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); \ + if( !pSeq ) \ + { \ + static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); \ + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); \ + pSeq = &aSeq; \ + } \ + } \ + return *pSeq; \ +} \ +\ +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 == rtl_compareMemory( 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 == rtl_compareMemory( 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_ + diff --git a/comphelper/inc/comphelper/serviceinfohelper.hxx b/comphelper/inc/comphelper/serviceinfohelper.hxx new file mode 100644 index 000000000000..87e450260b51 --- /dev/null +++ b/comphelper/inc/comphelper/serviceinfohelper.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: unoprov.hxx,v $ + * $Revision: 1.5 $ + * + * 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_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 ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // helper + static ::com::sun::star::uno::Sequence< ::rtl::OUString > concatSequences( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rSeq1, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rSeq2 ) throw(); + static void addToSequence( ::com::sun::star::uno::Sequence< ::rtl::OUString >& rSeq, sal_uInt16 nServices, /* sal_Char* */... ) throw(); + static sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& SupportedServices ) throw(); +}; + +} + +#endif + diff --git a/comphelper/inc/comphelper/sharedmutex.hxx b/comphelper/inc/comphelper/sharedmutex.hxx new file mode 100644 index 000000000000..c57c241f1cbb --- /dev/null +++ b/comphelper/inc/comphelper/sharedmutex.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * 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_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 diff --git a/comphelper/inc/comphelper/stillreadwriteinteraction.hxx b/comphelper/inc/comphelper/stillreadwriteinteraction.hxx new file mode 100644 index 000000000000..1ade47220c6f --- /dev/null +++ b/comphelper/inc/comphelper/stillreadwriteinteraction.hxx @@ -0,0 +1,69 @@ +/************************************************************************* +* +* 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_STILLREADWRITEINTERACTION_HXX_ +#define _COMPHELPER_STRILLREADWRITEINTERACTION_HXX_ + +//_______________________________________________ +// includes +#include <ucbhelper/interceptedinteraction.hxx> + +#ifndef __COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP__ +#include <com/sun/star/task/XInteractionHandler.hpp> +#endif + +#include <ucbhelper/interceptedinteraction.hxx> +#include "comphelper/comphelperdllapi.h" + +//_______________________________________________ +// namespace + +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 diff --git a/comphelper/inc/comphelper/stl_types.hxx b/comphelper/inc/comphelper/stl_types.hxx new file mode 100644 index 000000000000..7a8a56f5f238 --- /dev/null +++ b/comphelper/inc/comphelper/stl_types.hxx @@ -0,0 +1,282 @@ +/************************************************************************* + * + * 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_STLTYPES_HXX_ +#define _COMPHELPER_STLTYPES_HXX_ + +#if !defined(__SGI_STL_VECTOR_H) || !defined(__SGI_STL_MAP_H) || !defined(__SGI_STL_MULTIMAP_H) + +#include <vector> +#include <map> + +#include <stack> +#include <set> + +#ifdef _MSC_VER +# ifndef _USE_MATH_DEFINES +# define _USE_MATH_DEFINES // needed by Visual C++ for math constants +# endif +#endif + +#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> + +//... namespace comphelper ................................................ +namespace comphelper +{ +//......................................................................... + +//======================================================================== +// comparisation functions + +//------------------------------------------------------------------------ + struct UStringLess : public ::std::binary_function< ::rtl::OUString, ::rtl::OUString, bool> +{ + bool operator() (const ::rtl::OUString& x, const ::rtl::OUString& y) const { return x < y ? true : false;} // construct prevents a MSVC6 warning +}; +//------------------------------------------------------------------------ +struct UStringMixLess : public ::std::binary_function< ::rtl::OUString, ::rtl::OUString, bool> +{ + bool m_bCaseSensitive; +public: + UStringMixLess(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){} + bool operator() (const ::rtl::OUString& x, const ::rtl::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 ::rtl::OUString& lhs, const ::rtl::OUString& rhs) const { return lhs.equals( rhs );} +}; + +//------------------------------------------------------------------------ +struct UStringIEqual +{ + sal_Bool operator() (const ::rtl::OUString& lhs, const ::rtl::OUString& rhs) const { return lhs.equalsIgnoreAsciiCase( rhs );} +}; + +//------------------------------------------------------------------------ +struct UStringHash +{ + size_t operator() (const ::rtl::OUString& rStr) const {return rStr.hashCode();} +}; + +//------------------------------------------------------------------------ +class UStringMixEqual +{ + sal_Bool m_bCaseSensitive; + +public: + UStringMixEqual(sal_Bool bCaseSensitive = sal_True):m_bCaseSensitive(bCaseSensitive){} + sal_Bool operator() (const ::rtl::OUString& lhs, const ::rtl::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< ::rtl::OUString,::rtl::OUString,bool> +{ + sal_Bool m_bCaseSensitive; + +public: + TStringMixEqualFunctor(sal_Bool bCaseSensitive = sal_True) + :m_bCaseSensitive(bCaseSensitive) + {} + bool operator() (const ::rtl::OUString& lhs, const ::rtl::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,::rtl::OUString,bool> +{ +public: + TPropertyValueEqualFunctor() + {} + bool operator() (const ::com::sun::star::beans::PropertyValue& lhs, const ::rtl::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 ::rtl::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(::rtl::OUStringBuffer & i_rBuffer) + : m_rBuffer(i_rBuffer) { } + Self & operator=(::rtl::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: + ::rtl::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(::rtl::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 + +#endif // _COMPHELPER_STLTYPES_HXX_ + diff --git a/comphelper/inc/comphelper/stlunosequence.hxx b/comphelper/inc/comphelper/stlunosequence.hxx new file mode 100644 index 000000000000..d9757bbd9b51 --- /dev/null +++ b/comphelper/inc/comphelper/stlunosequence.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * 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_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 diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx new file mode 100644 index 000000000000..b613ddd2c5f1 --- /dev/null +++ b/comphelper/inc/comphelper/storagehelper.hxx @@ -0,0 +1,169 @@ +/************************************************************************* + * + * 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_STORAGEHELPER_HXX +#define _COMPHELPER_STORAGEHELPER_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XStream.hpp> +#include "comphelper/comphelperdllapi.h" + + +#define PACKAGE_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageFormat" ) ) +#define ZIP_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) +#define OFOPXML_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) + +namespace comphelper { + +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::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + 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::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + 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::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + 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 ::rtl::OUString& aURL, + sal_Int32 nStorageMode, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + 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 ::rtl::OUString& aURL, + sal_Int32 nStorageMode, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + + 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::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + 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::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + 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 ::rtl::OUString& aURL, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + throw ( ::com::sun::star::uno::Exception ); + + static void SetCommonStoragePassword( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::rtl::OUString& aPass ) + 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 ); + + // The followin methods are related to creation of a storage of specified format + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetTemporaryStorageOfFormat( + const ::rtl::OUString& aFormat, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageOfFormatFromURL( + const ::rtl::OUString& aFormat, + const ::rtl::OUString& aURL, + sal_Int32 nStorageMode, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), + sal_Bool bRepairStorage = sal_False ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageOfFormatFromInputStream( + const ::rtl::OUString& aFormat, + const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), + sal_Bool bRepairStorage = sal_False ) + throw ( ::com::sun::star::uno::Exception ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > + GetStorageOfFormatFromStream( + const ::rtl::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::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), + sal_Bool bRepairStorage = sal_False ) + throw ( ::com::sun::star::uno::Exception ); + + static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ); + static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); +}; + +} + +#endif + diff --git a/comphelper/inc/comphelper/streamsection.hxx b/comphelper/inc/comphelper/streamsection.hxx new file mode 100644 index 000000000000..e3b8d4ebfe8f --- /dev/null +++ b/comphelper/inc/comphelper/streamsection.hxx @@ -0,0 +1,88 @@ +/************************************************************************* + * + * 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_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(); + /** + return the number of bytes which are still available + */ + sal_Int32 available(); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_STREAMSECTION_HXX_ diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx new file mode 100644 index 000000000000..8c262edaddfe --- /dev/null +++ b/comphelper/inc/comphelper/string.hxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * 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 INCLUDED_COMPHELPER_STRING_HXX +#define INCLUDED_COMPHELPER_STRING_HXX + +#include "sal/config.h" + +#include <cstddef> +#include "comphelper/comphelperdllapi.h" +#include "sal/types.h" +#include <com/sun/star/uno/Sequence.hxx> + + +namespace rtl { class OUString; } + +// rtl::OUString helper functions that are not widespread or mature enough to +// go into the stable URE API: +namespace comphelper { namespace string { + +/** + Replace the first occurrence of a substring with another string. + + @param source + The source string, in which the search will take place. + + @param from + The ASCII substring to search for. Must point to at least fromLength ASCII + characters. + + @param fromLength + The length of the from substring. Must not be negative. + + @param to + The string to use as replacement. + + @param beginAt + The index at which to begin the search. Must be between zero and the length + of source, inclusive. + + @param replacedAt + If non-null, receives the starting index at which the replacement took place + or -1 if from was not found. + + @return + The resulting string, in which the replacement has taken place. +*/ +COMPHELPER_DLLPUBLIC rtl::OUString searchAndReplaceAsciiL( + rtl::OUString const & source, char const * from, sal_Int32 fromLength, + rtl::OUString const & to, sal_Int32 beginAt = 0, + sal_Int32 * replacedAt = NULL); + +/** replaces, in the given source string, all occurences of a given ASCII pattern + with another ASCII pattern +*/ +COMPHELPER_DLLPUBLIC ::rtl::OUString searchAndReplaceAllAsciiWithAscii( + const ::rtl::OUString& source, const sal_Char* from, const sal_Char* to, + const sal_Int32 beginAt = 0 ); + +/** does an in-place replacement of the first occurance of a sub string with + another string + + @param source + the string to search and replace in. + @param asciiPattern + the ASCII sub string to search for. Must point to a 0-terminated string. + @param replace + The string to use as replacement. + @param beginAt + The index at which to begin the search. Must be between zero and the length + of source, inclusive. + + @param replacedAt + If non-null, receives the starting index at which the replacement took place + or -1 if from was not found. + + @return + a reference to <code>source</code> +*/ +COMPHELPER_DLLPUBLIC ::rtl::OUString& + searchAndReplaceAsciiI( ::rtl::OUString & source, sal_Char const * asciiPattern, + ::rtl::OUString const & replace, sal_Int32 beginAt = 0, + sal_Int32 * replacedAt = NULL ); + +/** 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 ::rtl::OUString convertCommaSeparated( + ::com::sun::star::uno::Sequence< ::rtl::OUString > const & i_rSeq); + +/** 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< ::rtl::OUString > + convertCommaSeparated( ::rtl::OUString const & i_rString ); + +} } + +#endif diff --git a/comphelper/inc/comphelper/synchronousdispatch.hxx b/comphelper/inc/comphelper/synchronousdispatch.hxx new file mode 100644 index 000000000000..b215ec2b990b --- /dev/null +++ b/comphelper/inc/comphelper/synchronousdispatch.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * 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_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 rtl { class OUString; } + +//........................................................................ +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 rtl::OUString &sURL, + const rtl::OUString &sTarget, + const sal_Int32 nFlags, + const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &lArguments ); + }; + +//........................................................................ +} // namespace comphelper +//........................................................................ + +#endif // _COMPHELPER_SYNCHRONOUSDISPATCH_HXX + diff --git a/comphelper/inc/comphelper/types.hxx b/comphelper/inc/comphelper/types.hxx new file mode 100644 index 000000000000..8d5b9f744451 --- /dev/null +++ b/comphelper/inc/comphelper/types.hxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * 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_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< ::rtl::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* pDummy) + { + 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_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 ::rtl::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_ + diff --git a/comphelper/inc/comphelper/uieventslogger.hxx b/comphelper/inc/comphelper/uieventslogger.hxx new file mode 100644 index 000000000000..5cf270751dd1 --- /dev/null +++ b/comphelper/inc/comphelper/uieventslogger.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * 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_UIEVENTSLOGGER_HXX +#define _COMPHELPER_UIEVENTSLOGGER_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/util/URL.hpp> +#include <comphelper/comphelperdllapi.h> +#include <rtl/ustring.hxx> + + +namespace comphelper +{ + // this class is part of the OOo Improvement Program Core + class COMPHELPER_DLLPUBLIC UiEventsLogger + { + public: + static sal_Bool isEnabled(); + static sal_Int32 getSessionLogEventCount(); + static void appendDispatchOrigin( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& args, const ::rtl::OUString& originapp, const ::rtl::OUString& originwidget); + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> purgeDispatchOrigin(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& args); + static void logDispatch(const ::com::sun::star::util::URL& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& args); + static void logVcl(const ::rtl::OUString& parent_id, sal_Int32 window_type, const ::rtl::OUString& id, const ::rtl::OUString& method, const ::rtl::OUString& param); + static void logVcl(const ::rtl::OUString& parent_id, sal_Int32 window_type, const ::rtl::OUString& id, const ::rtl::OUString& method, sal_Int32 param); + static void logVcl(const ::rtl::OUString& parent_id, sal_Int32 window_type, const ::rtl::OUString& id, const ::rtl::OUString& method); + static void disposing(); + static void reinit(); + virtual ~UiEventsLogger() {} + }; +} +#endif diff --git a/comphelper/inc/comphelper/uno3.hxx b/comphelper/inc/comphelper/uno3.hxx new file mode 100644 index 000000000000..cd6196e50e53 --- /dev/null +++ b/comphelper/inc/comphelper/uno3.hxx @@ -0,0 +1,302 @@ +/************************************************************************* + * + * 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_UNO3_HXX_ +#define _COMPHELPER_UNO3_HXX_ + +#include <osl/interlck.h> +#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_incrementInterlockedCount(&_counter); } + inline oslInterlockedCount decrement(oslInterlockedCount& _counter) { return osl_decrementInterlockedCount(&_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 ) \ + ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL classname::getImplementationId( ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + static ::cppu::OImplementationId* pId = NULL; \ + if (!pId) \ + { \ + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); \ + if (!pId) \ + { \ + static ::cppu::OImplementationId aId; \ + pId = &aId; \ + } \ + } \ + return pId->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; + } + #define FORWARD_DECLARE_INTERFACE(NAME,XFACE) \ + namespace com \ + { \ + namespace sun \ + {\ + namespace star \ + {\ + namespace NAME \ + {\ + class XFACE; \ + }\ + }\ + }\ + }\ + + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_UNO3_HXX_ + diff --git a/comphelper/inc/comphelper/unwrapargs.hxx b/comphelper/inc/comphelper/unwrapargs.hxx new file mode 100644 index 000000000000..652187f9139f --- /dev/null +++ b/comphelper/inc/comphelper/unwrapargs.hxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#if ! defined(COMPHELPER_UNWRAPARGS_HXX_INCLUDED) +#define COMPHELPER_UNWRAPARGS_HXX_INCLUDED + +#if ! defined(_RTL_USTRBUF_HXX_) +#include "rtl/ustrbuf.hxx" +#endif +#include "com/sun/star/uno/Sequence.hxx" +#if ! defined(_COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_) +#include "com/sun/star/lang/IllegalArgumentException.hpp" +#endif +#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( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "No such argument available!") ), + xErrorContext, static_cast<sal_Int16>(nArg) ); + } + if (! (seq[nArg] >>= v)) { + ::rtl::OUStringBuffer buf; + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("Cannot extract ANY { ") ); + buf.append( seq[nArg].getValueType().getTypeName() ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" } 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, ~) \ +} + +#if ! defined(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) + diff --git a/comphelper/inc/comphelper/weak.hxx b/comphelper/inc/comphelper/weak.hxx new file mode 100644 index 000000000000..b23b673e9b1c --- /dev/null +++ b/comphelper/inc/comphelper/weak.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * 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_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 + + diff --git a/comphelper/inc/comphelper/weakbag.hxx b/comphelper/inc/comphelper/weakbag.hxx new file mode 100644 index 000000000000..8b2fa1c4449d --- /dev/null +++ b/comphelper/inc/comphelper/weakbag.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * 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 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 List::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 > > List; + + List m_list; +}; + +} + +#endif diff --git a/comphelper/inc/comphelper/weakeventlistener.hxx b/comphelper/inc/comphelper/weakeventlistener.hxx new file mode 100644 index 000000000000..930f19f3a40f --- /dev/null +++ b/comphelper/inc/comphelper/weakeventlistener.hxx @@ -0,0 +1,189 @@ +/************************************************************************* + * + * 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_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 + + diff --git a/comphelper/inc/makefile.mk b/comphelper/inc/makefile.mk new file mode 100644 index 000000000000..5c466f93be42 --- /dev/null +++ b/comphelper/inc/makefile.mk @@ -0,0 +1,48 @@ +#************************************************************************* +# +# 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. +# +#************************************************************************* +PRJ=.. + +PRJNAME=comphelper +TARGET=inc + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + +.IF "$(ENABLE_PCH)"!="" +ALLTAR : \ + $(SLO)$/precompiled.pch \ + $(SLO)$/precompiled_ex.pch + +.ENDIF # "$(ENABLE_PCH)"!="" + diff --git a/comphelper/inc/pch/precompiled_comphelper.cxx b/comphelper/inc/pch/precompiled_comphelper.cxx new file mode 100644 index 000000000000..2936d22924b7 --- /dev/null +++ b/comphelper/inc/pch/precompiled_comphelper.cxx @@ -0,0 +1,29 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +#include "precompiled_comphelper.hxx" + diff --git a/comphelper/inc/pch/precompiled_comphelper.hxx b/comphelper/inc/pch/precompiled_comphelper.hxx new file mode 100644 index 000000000000..a3679864b3b1 --- /dev/null +++ b/comphelper/inc/pch/precompiled_comphelper.hxx @@ -0,0 +1,32 @@ +/************************************************************************* + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): Generated on 2006-09-01 17:49:34.253143 + +#ifdef PRECOMPILED_HEADERS +#endif + |