diff options
Diffstat (limited to 'unotools/inc')
46 files changed, 6847 insertions, 0 deletions
diff --git a/unotools/inc/makefile.mk b/unotools/inc/makefile.mk new file mode 100644 index 000000000000..d6c17aaecb89 --- /dev/null +++ b/unotools/inc/makefile.mk @@ -0,0 +1,52 @@ +#************************************************************************* +# +# 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: makefile.mk,v $ +# +# $Revision: 1.3 $ +# +# 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=unotools +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/unotools/inc/pch/precompiled_unotools.cxx b/unotools/inc/pch/precompiled_unotools.cxx new file mode 100644 index 000000000000..a848d922583c --- /dev/null +++ b/unotools/inc/pch/precompiled_unotools.cxx @@ -0,0 +1,32 @@ +/************************************************************************* + * + * 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: precompiled_unotools.cxx,v $ + * $Revision: 1.3 $ + * + * 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_unotools.hxx" + diff --git a/unotools/inc/pch/precompiled_unotools.hxx b/unotools/inc/pch/precompiled_unotools.hxx new file mode 100644 index 000000000000..30979736a134 --- /dev/null +++ b/unotools/inc/pch/precompiled_unotools.hxx @@ -0,0 +1,35 @@ +/************************************************************************* + * + * 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: precompiled_unotools.hxx,v $ + * $Revision: 1.3 $ + * + * 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:50:16.701453 + +#ifdef PRECOMPILED_HEADERS +#endif + diff --git a/unotools/inc/unotools/accessiblerelationsethelper.hxx b/unotools/inc/unotools/accessiblerelationsethelper.hxx new file mode 100644 index 000000000000..e48850e3efc8 --- /dev/null +++ b/unotools/inc/unotools/accessiblerelationsethelper.hxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * 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: accessiblerelationsethelper.hxx,v $ + * $Revision: 1.6 $ + * + * 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 _UTL_ACCESSIBLERELATIONSETHELPER_HXX_ +#define _UTL_ACCESSIBLERELATIONSETHELPER_HXX_ + +#include "unotools/unotoolsdllapi.h" + +#ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESSTATESET_HPP_ +#include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> +#endif +#include <com/sun/star/uno/Reference.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XServiceName.hpp> +#include <vos/mutex.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/servicehelper.hxx> + +class AccessibleRelationSetHelperImpl; + +//========================================================================= +//= XAccessibleRelationSet helper classes +//========================================================================= + +//... namespace utl ....................................................... +namespace utl +{ +//......................................................................... + +/** @descr + This base class provides an implementation of the + <code>AccessibleRelationSet</code> service. +*/ +class UNOTOOLS_DLLPUBLIC AccessibleRelationSetHelper + : public cppu::WeakImplHelper1< + ::com::sun::star::accessibility::XAccessibleRelationSet + > +{ +public: + //===== internal ======================================================== + AccessibleRelationSetHelper (); + AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper); +protected: + virtual ~AccessibleRelationSetHelper (void); +public: + + //===== XAccessibleRelationSet ========================================== + + /** Returns the number of relations in this relation set. + + @return + Returns the number of relations or zero if there are none. + */ + virtual sal_Int32 SAL_CALL getRelationCount( ) + throw (::com::sun::star::uno::RuntimeException); + + /** Returns the relation of this relation set that is specified by + the given index. + + @param nIndex + This index specifies the relatio to return. + + @return + For a valid index, i.e. inside the range 0 to the number of + relations minus one, the returned value is the requested + relation. If the index is invalid then the returned relation + has the type INVALID. + + */ + virtual ::com::sun::star::accessibility::AccessibleRelation SAL_CALL + getRelation( sal_Int32 nIndex ) + throw (::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::uno::RuntimeException); + + /** Tests whether the relation set contains a relation matching the + specified key. + + @param aRelationType + The type of relation to look for in this set of relations. This + has to be one of the constants of + <type>AccessibleRelationType</type>. + + @return + Returns <TRUE/> if there is a (at least one) relation of the + given type and <FALSE/> if there is no such relation in the set. + */ + virtual sal_Bool SAL_CALL containsRelation( sal_Int16 aRelationType ) + throw (::com::sun::star::uno::RuntimeException); + + /** Retrieve and return the relation with the given relation type. + + @param aRelationType + The type of the relation to return. This has to be one of the + constants of <type>AccessibleRelationType</type>. + + @return + If a relation with the given type could be found than (a copy + of) this relation is returned. Otherwise a relation with the + type INVALID is returned. + */ + virtual ::com::sun::star::accessibility::AccessibleRelation SAL_CALL + getRelationByType( sal_Int16 aRelationType ) + throw (::com::sun::star::uno::RuntimeException); + + void AddRelation( + const ::com::sun::star::accessibility::AccessibleRelation& rRelation) + throw (::com::sun::star::uno::RuntimeException); + + //===== XTypeProvider =================================================== + + /** Returns a sequence of all supported interfaces. + */ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL + getTypes (void) + throw (::com::sun::star::uno::RuntimeException); + + /** Returns a implementation id. + */ + virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL + getImplementationId (void) + throw (::com::sun::star::uno::RuntimeException); + +protected: + /// Mutex guarding this object. + ::vos::OMutex maMutex; + +private: + /// The implementation of this helper interface. + AccessibleRelationSetHelperImpl* mpHelperImpl; +}; + +//......................................................................... +} +//... namespace utl ....................................................... +#endif diff --git a/unotools/inc/unotools/accessiblestatesethelper.hxx b/unotools/inc/unotools/accessiblestatesethelper.hxx new file mode 100644 index 000000000000..421a77b78f2b --- /dev/null +++ b/unotools/inc/unotools/accessiblestatesethelper.hxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * 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: accessiblestatesethelper.hxx,v $ + * $Revision: 1.13 $ + * + * 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 _UTL_ACCESSIBLESTATESETHELPER_HXX_ +#define _UTL_ACCESSIBLESTATESETHELPER_HXX_ + +#include "unotools/unotoolsdllapi.h" + +#ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESSTATESET_HPP_ +#include <com/sun/star/accessibility/XAccessibleStateSet.hpp> +#endif +#include <com/sun/star/uno/Reference.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XServiceName.hpp> +#include <vos/mutex.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/servicehelper.hxx> + +class AccessibleStateSetHelperImpl; + +//========================================================================= +//= XAccessibleStateSet helper classes +//========================================================================= + +//... namespace utl ....................................................... +namespace utl +{ +//......................................................................... + +/** @descr + This base class provides an implementation of the + <code>AccessibleStateSet</code> service. +*/ +class UNOTOOLS_DLLPUBLIC AccessibleStateSetHelper + : public cppu::WeakImplHelper1< + ::com::sun::star::accessibility::XAccessibleStateSet + > +{ +public: + //===== internal ======================================================== + + AccessibleStateSetHelper (); + /** constructs an object with some states initially set + + <p>This ctor is compatible with + <method scope="comphelper">OAccessibleImplementationAccess::implGetForeignControlledStates</method></p> + + @param _nInitialStates + is a bit mask. Every bit 2^n means that the state number n (as got from the + AccessibleStateType constants) should be set initially. + */ + AccessibleStateSetHelper ( const sal_Int64 _nInitialStates ); + + AccessibleStateSetHelper ( const AccessibleStateSetHelper& rHelper ); +protected: + virtual ~AccessibleStateSetHelper (void); +public: + + //===== XAccessibleStateSet ============================================== + + /** Checks whether the current state set is empty. + + @return + Returns <TRUE/> if there is no state in this state set and + <FALSE/> if there is at least one state set in it. + */ + virtual sal_Bool SAL_CALL isEmpty () + throw (::com::sun::star::uno::RuntimeException); + + /** Checks if the given state is a member of the state set of this + object. + + @param aState + The state for which to check membership. This has to be one of + the constants of <type>AccessibleStateType</type>. + + @return + Returns <TRUE/> if the given state is a memeber of this object's + state set and <FALSE/> otherwise. + */ + virtual sal_Bool SAL_CALL contains (sal_Int16 aState) + throw (::com::sun::star::uno::RuntimeException); + + /** Checks if all of the given states are in this object's state + set. + + @param aStateSet + This sequence of states is interpreted as set and every of its + members, duplicates are ignored, is checked for membership in + this object's state set. Each state has to be one of the + constants of <type>AccessibleStateType</type>. + + @return + Returns <TRUE/> if all states of the given state set are members + of this object's state set. <FALSE/> is returned if at least + one of the states in the given state is not a member of this + object's state set. + */ + virtual sal_Bool SAL_CALL containsAll ( + const ::com::sun::star::uno::Sequence<sal_Int16>& rStateSet) + throw (::com::sun::star::uno::RuntimeException); + + /** Returns a sequence of all states. + */ + virtual com::sun::star::uno::Sequence<sal_Int16> SAL_CALL getStates() + throw (::com::sun::star::uno::RuntimeException); + + /** Adds a state to the set. + */ + void AddState(sal_Int16 aState) + throw (::com::sun::star::uno::RuntimeException); + + /** Removes a state from the set if the set contains the state, otherwise nothing is done. + */ + void RemoveState(sal_Int16 aState) + throw (::com::sun::star::uno::RuntimeException); + + /** Compares the set with the set given by rComparativeValue and puts the results + into rOldStates and rNewStates. + + rOldStates contains after call all states which are in the own set and + not in the comparative set. + + rNewStates contains after call all states which are in the comparative + set and not in the own set. + */ + sal_Bool Compare(const AccessibleStateSetHelper& rComparativeValue, + AccessibleStateSetHelper& rOldStates, + AccessibleStateSetHelper& rNewStates) + throw (::com::sun::star::uno::RuntimeException); + + //===== XTypeProvider =================================================== + + /** Returns a sequence of all supported interfaces. + */ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL + getTypes (void) + throw (::com::sun::star::uno::RuntimeException); + + /** Returns a implementation id. + */ + virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL + getImplementationId (void) + throw (::com::sun::star::uno::RuntimeException); + +protected: + /// Mutex guarding this object. + ::vos::OMutex maMutex; + +private: + /// The implementation of this helper interface. + AccessibleStateSetHelperImpl* mpHelperImpl; +}; + +//......................................................................... +} +//... namespace utl ....................................................... +#endif diff --git a/unotools/inc/unotools/atom.hxx b/unotools/inc/unotools/atom.hxx new file mode 100644 index 000000000000..e8409f6ce5e6 --- /dev/null +++ b/unotools/inc/unotools/atom.hxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * 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: atom.hxx,v $ + * $Revision: 1.9 $ + * + * 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 _UTL_ATOM_HXX_ +#define _UTL_ATOM_HXX_ + +#include "unotools/unotoolsdllapi.h" +#include <rtl/ustring.hxx> +#include <osl/mutex.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <hash_map> +#ifndef __SGI_STL_LIST +#include <list> +#endif +#include <com/sun/star/util/XAtomServer.hpp> + +#define INVALID_ATOM 0 + +namespace utl { + + struct AtomDescription + { + int atom; + ::rtl::OUString description; + }; + + class AtomProvider + { + int m_nAtoms; + ::std::hash_map< int, ::rtl::OUString, ::std::hash< int > > m_aStringMap; + ::std::hash_map< ::rtl::OUString, int, ::rtl::OUStringHash > m_aAtomMap; + public: + AtomProvider(); + ~AtomProvider(); + + int getAtom( const ::rtl::OUString&, sal_Bool bCreate = sal_False ); + int getLastAtom() const { return m_nAtoms-1; } + const ::rtl::OUString& getString( int ) const; + + void getAll( ::std::list< AtomDescription >& atoms ); + + void getRecent( int atom, ::std::list< AtomDescription >& atoms ); + + void overrideAtom( int atom, const ::rtl::OUString& description ); + + sal_Bool hasAtom( int atom ) const; + }; + + + class UNOTOOLS_DLLPUBLIC MultiAtomProvider + { + ::std::hash_map< int, AtomProvider*, ::std::hash< int > > m_aAtomLists; + public: + MultiAtomProvider(); + ~MultiAtomProvider(); + + int getLastAtom( int atomClass ) const; + + sal_Bool insertAtomClass( int atomClass ); + + int getAtom( int atomClass, const ::rtl::OUString& rString, sal_Bool bCreate = sal_False ); + + void getRecent( int atomClass, int atom, ::std::list< AtomDescription >& atoms ); + + const ::rtl::OUString& getString( int atomClass, int atom ) const; + void getClass( int atomClass, ::std::list< AtomDescription >& atoms ) const; + + void overrideAtom( int atomClass, int atom, const ::rtl::OUString& description ); + void overrideAtom( int atomClass, const ::com::sun::star::util::AtomDescription& newDescription ) + { overrideAtom( atomClass, newDescription.atom, newDescription.description ); } + sal_Bool hasAtom( int atomClass, int atom ) const; + }; + + class AtomServer : public ::cppu::WeakAggImplHelper1< ::com::sun::star::util::XAtomServer > + { + private: + MultiAtomProvider m_aProvider; + ::osl::Mutex m_aMutex; + public: + AtomServer(); + virtual ~AtomServer(); + + const ::rtl::OUString& getString( int atomClass, int atom ) const + { return m_aProvider.getString( atomClass, atom ); } + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > SAL_CALL getClass( sal_Int32 atomClass ) throw(); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > > SAL_CALL getClasses( const ::com::sun::star::uno::Sequence< sal_Int32 >& atomClasses ) throw(); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAtomDescriptions( const ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomClassRequest >& atoms ) throw(); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::AtomDescription > SAL_CALL getRecentAtoms( sal_Int32 atomClass, sal_Int32 atom ) throw(); + virtual sal_Int32 SAL_CALL getAtom( sal_Int32 atomClass, const ::rtl::OUString& description, sal_Bool create ) throw(); + }; + + class AtomClient + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::util::XAtomServer > m_xServer; + MultiAtomProvider m_aProvider; + public: + AtomClient( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XAtomServer >& ); + ~AtomClient(); + + void updateAtomClasses( const ::com::sun::star::uno::Sequence< sal_Int32 >& atomClasses ); + int getAtom( int atomClass, const ::rtl::OUString& description, sal_Bool bCreate ); + const ::rtl::OUString& getString( int atomClass, int atom ); + }; +} + +#endif diff --git a/unotools/inc/unotools/bootstrap.hxx b/unotools/inc/unotools/bootstrap.hxx new file mode 100644 index 000000000000..d2c8a5f1875b --- /dev/null +++ b/unotools/inc/unotools/bootstrap.hxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * 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: bootstrap.hxx,v $ + * $Revision: 1.15.16.1 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UTL_BOOTSTRAP_HXX +#define _UTL_BOOTSTRAP_HXX + +namespace rtl +{ + class OUString; +} + +namespace utl +{ +//----------------------------------------------------------------------------- + /** provides configuration information needed for application startup. + <p>This class handles the startup information for the office application. + It encapsulates knowledge of how to retriev such information and how + to diagnose failures to retriev required data. + </p> + */ + class UNOTOOLS_DLLPUBLIC Bootstrap + { + // the static interface + public: // some common information items + + /// retrieve the product key; defaults to executable name (without extension) + static rtl::OUString getProductKey(); + + /// retrieve the product key; uses the given default, if not found + static rtl::OUString getProductKey(rtl::OUString const& _sDefault); + + /// retrieve the product source (MWS name) + static ::rtl::OUString getProductSource(rtl::OUString const& _sDefault); + + /// retrieve the BUILDID information item; uses the given default, if not found + static rtl::OUString getBuildIdData(rtl::OUString const& _sDefault); + + /// retrieve the ALLUSERS information item from setup.ini file; uses the given default, if not found + static rtl::OUString getAllUsersValue(rtl::OUString const& _sDefault); + + /// reload cached data + static void reloadData(); + + public: // retrieve path information about the installatíon location + enum PathStatus + { + PATH_EXISTS, // Success: Found a path to an existing file or directory + PATH_VALID, // Found a valid path, but the file or directory does not exist + DATA_INVALID, // Retrieved a string for this path, that is not a valid file url or system path + DATA_MISSING, // Could not retrieve any data for this path + DATA_UNKNOWN // No attempt to retrieve data for this path was made + }; + + /// get a file URL to the common base installation [${insturl}] + static PathStatus locateBaseInstallation(rtl::OUString& _rURL); + + /// get a file URL to the user installation [${userurl}] + static PathStatus locateUserInstallation(rtl::OUString& _rURL); + + /// get a file URL to the shared data directory [default is ${insturl}/share] + static PathStatus locateSharedData(rtl::OUString& _rURL); + + /// get a file URL to the user data directory [default is ${userurl}/user] + static PathStatus locateUserData(rtl::OUString& _rURL); + + // the next two items are mainly supported for diagnostic purposes. both items may be unused + /// get a file URL to the bootstrap INI file used [e.g. ${insturl}/program/bootraprc] + static PathStatus locateBootstrapFile(rtl::OUString& _rURL); + /// get a file URL to the version locator INI file used [e.g. ${SYSUSERCONFIG}/sversion.ini] + static PathStatus locateVersionFile(rtl::OUString& _rURL); + + public: // evaluate the validity of the installation + /// high-level status of bootstrap success + enum Status + { + DATA_OK, /// user-dir and share-dir do exist, product key found or can be defaulted to exe-name + MISSING_USER_INSTALL, /// ${userurl} does not exist; or version-file cannot be found or is invalid + INVALID_USER_INSTALL, /// can locate ${userurl}, but user-dir is missing + INVALID_BASE_INSTALL /// other failure: e.g. cannot locate share-dir; bootstraprc missing or invalid; no product key + }; + + /// error code for detailed diagnostics of bootstrap failures + enum FailureCode + { + NO_FAILURE, /// bootstrap was successful + MISSING_INSTALL_DIRECTORY, /// the shared installation directory could not be located + MISSING_BOOTSTRAP_FILE, /// the bootstrap INI file could not be found or read + MISSING_BOOTSTRAP_FILE_ENTRY, /// the bootstrap INI is missing a required entry + INVALID_BOOTSTRAP_FILE_ENTRY, /// the bootstrap INI contains invalid data + MISSING_VERSION_FILE, /// the version locator INI file could not be found or read + MISSING_VERSION_FILE_ENTRY, /// the version locator INI has no entry for this version + INVALID_VERSION_FILE_ENTRY, /// the version locator INI entry is not a valid directory URL + MISSING_USER_DIRECTORY, /// the user installation directory does not exist + INVALID_BOOTSTRAP_DATA /// some bootstrap data was invalid in unexpected ways + }; + + /// Evaluates the status of the installation and returns a diagnostic message corresponding to this status + static Status checkBootstrapStatus(rtl::OUString& _rDiagnosticMessage); + + /** Evaluates the status of the installation and returns a diagnostic + message and error code corresponding to this status + */ + static Status checkBootstrapStatus(rtl::OUString& _rDiagnosticMessage, FailureCode& _rErrCode); + + public: + // singleton impl-class + class Impl; + static Impl const& data(); // the data related to the bootstrap.ini file + }; +//----------------------------------------------------------------------------- +} // namespace utl + +#endif // _UTL_BOOTSTRAP_HXX diff --git a/unotools/inc/unotools/calendarwrapper.hxx b/unotools/inc/unotools/calendarwrapper.hxx new file mode 100644 index 000000000000..c98e0867e8fa --- /dev/null +++ b/unotools/inc/unotools/calendarwrapper.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * 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: calendarwrapper.hxx,v $ + * $Revision: 1.10.24.1 $ + * + * 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 _UNOTOOLS_CALENDARWRAPPER_HXX +#define _UNOTOOLS_CALENDARWRAPPER_HXX + +#include <tools/datetime.hxx> +#include <tools/string.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/i18n/Calendar.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include "unotools/unotoolsdllapi.h" + +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + +namespace com { namespace sun { namespace star { + namespace i18n { + class XExtendedCalendar; + } +}}} + + +class UNOTOOLS_DLLPUBLIC CalendarWrapper +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XExtendedCalendar > xC; + + DateTime aEpochStart; // 1Jan1970 + +public: + CalendarWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF + ); + ~CalendarWrapper(); + + + // wrapper implementations of XCalendar + + void loadDefaultCalendar( const ::com::sun::star::lang::Locale& rLocale ); + void loadCalendar( const ::rtl::OUString& rUniqueID, const ::com::sun::star::lang::Locale& rLocale ); + ::com::sun::star::i18n::Calendar getLoadedCalendar() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > getAllCalendars( const ::com::sun::star::lang::Locale& rLocale ) const; + ::rtl::OUString getUniqueID() const; + /// set UTC date/time + void setDateTime( double nTimeInDays ); + /// get UTC date/time + double getDateTime() const; + /// convenience method to set local date/time + void setLocalDateTime( double nTimeInDays ); + /// convenience method to get local date/time + double getLocalDateTime() const; + + // wrapper implementations of XCalendar + + void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ); + sal_Bool isValid() const; + sal_Int16 getValue( sal_Int16 nFieldIndex ) const; + void addValue( sal_Int16 nFieldIndex, sal_Int32 nAmount ); + sal_Int16 getFirstDayOfWeek() const; + void setFirstDayOfWeek( sal_Int16 nDay ); + void setMinimumNumberOfDaysForFirstWeek( sal_Int16 nDays ); + sal_Int16 getMinimumNumberOfDaysForFirstWeek() const; + sal_Int16 getNumberOfMonthsInYear() const; + sal_Int16 getNumberOfDaysInWeek() const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getMonths() const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getDays() const; + String getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const; + + /** Convenience method to get timezone offset in milliseconds, taking both + fields ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS into account. */ + sal_Int32 getZoneOffsetInMillis() const; + /** Convenience method to get DST offset in milliseconds, taking both + fields DST_OFFSET and DST_OFFSET_SECOND_MILLIS into account. */ + sal_Int32 getDSTOffsetInMillis() const; + + // wrapper implementations of XExtendedCalendar + + String getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const; + + + // convenience methods + + /// get epoch start (should be 01Jan1970) + inline const DateTime& getEpochStart() const + { return aEpochStart; } + + /// set a local (!) Gregorian DateTime + inline void setGregorianDateTime( const DateTime& rDateTime ) + { setLocalDateTime( rDateTime - aEpochStart ); } + + /// get the DateTime as a local (!) Gregorian DateTime + inline DateTime getGregorianDateTime() const + { return aEpochStart + getLocalDateTime(); } + +private: + + /** get timezone or DST offset in milliseconds, fields are + CalendarFieldIndex ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS + respectively DST_OFFSET and DST_OFFSET_SECOND_MILLIS. + */ + sal_Int32 getCombinedOffsetInMillis( sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const; +}; + +#endif diff --git a/unotools/inc/unotools/charclass.hxx b/unotools/inc/unotools/charclass.hxx new file mode 100644 index 000000000000..3caf0ea3cc6d --- /dev/null +++ b/unotools/inc/unotools/charclass.hxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * 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: charclass.hxx,v $ + * $Revision: 1.13 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_CHARCLASS_HXX +#define _UNOTOOLS_CHARCLASS_HXX + +#include <ctype.h> // isdigit(), isalpha() +#include <tools/string.hxx> +#include <tools/solar.h> +#include <com/sun/star/i18n/KCharacterType.hpp> +#include <com/sun/star/i18n/KParseTokens.hpp> +#include <com/sun/star/i18n/KParseType.hpp> +#include <com/sun/star/i18n/ParseResult.hpp> +#include <com/sun/star/i18n/XCharacterClassification.hpp> +#include <osl/mutex.hxx> + +class String; +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + +const sal_Int32 nCharClassAlphaType = + ::com::sun::star::i18n::KCharacterType::UPPER | + ::com::sun::star::i18n::KCharacterType::LOWER | + ::com::sun::star::i18n::KCharacterType::TITLE_CASE; + +const sal_Int32 nCharClassAlphaTypeMask = + nCharClassAlphaType | + ::com::sun::star::i18n::KCharacterType::PRINTABLE | + ::com::sun::star::i18n::KCharacterType::BASE_FORM; + +const sal_Int32 nCharClassLetterType = + nCharClassAlphaType | + ::com::sun::star::i18n::KCharacterType::LETTER; + +const sal_Int32 nCharClassLetterTypeMask = + nCharClassAlphaTypeMask | + ::com::sun::star::i18n::KCharacterType::LETTER; + +const sal_Int32 nCharClassNumericType = + ::com::sun::star::i18n::KCharacterType::DIGIT; + +const sal_Int32 nCharClassNumericTypeMask = + nCharClassNumericType | + ::com::sun::star::i18n::KCharacterType::PRINTABLE | + ::com::sun::star::i18n::KCharacterType::BASE_FORM; + + +class UNOTOOLS_DLLPUBLIC CharClass +{ + ::com::sun::star::lang::Locale aLocale; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > xCC; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + mutable ::osl::Mutex aMutex; + + // not implemented, prevent usage + CharClass( const CharClass& ); + CharClass& operator=( const CharClass& ); + + // instantiate component somehow + void getComponentInstance(); + +public: + /// Preferred ctor with service manager specified + CharClass( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::lang::Locale& rLocale + ); + + /// Depricated ctor, tries to get a process service manager or to load the + /// library directly. + CharClass( + const ::com::sun::star::lang::Locale& rLocale + ); + + ~CharClass(); + + /// set a new Locale + void setLocale( const ::com::sun::star::lang::Locale& rLocale ); + + /// get current Locale + const ::com::sun::star::lang::Locale& getLocale() const; + + + /// isdigit() on ascii values + static inline sal_Bool isAsciiDigit( sal_Unicode c ) + { return c < 128 ? sal_Bool(isdigit( (unsigned char) c ) != 0) : sal_False; } + + /// isalpha() on ascii values + static inline sal_Bool isAsciiAlpha( sal_Unicode c ) + { return c < 128 ? sal_Bool(isalpha( (unsigned char) c ) != 0) : sal_False; } + + /// isalnum() on ascii values + static inline sal_Bool isAsciiAlphaNumeric( sal_Unicode c ) + { return c < 128 ? sal_Bool(isalnum( (unsigned char) c ) != 0) : sal_False; } + + /// isdigit() on ascii values of entire string + static sal_Bool isAsciiNumeric( const String& rStr ); + + /// isalpha() on ascii values of entire string + static sal_Bool isAsciiAlpha( const String& rStr ); + + /// isalnum() on ascii values of entire string + static sal_Bool isAsciiAlphaNumeric( const String& rStr ); + + /// whether type is pure alpha or not, e.g. return of getStringType + static inline sal_Bool isAlphaType( sal_Int32 nType ) + { + return ((nType & nCharClassAlphaType) != 0) && + ((nType & ~(nCharClassAlphaTypeMask)) == 0); + } + + /// whether type is pure numeric or not, e.g. return of getStringType + static inline sal_Bool isNumericType( sal_Int32 nType ) + { + return ((nType & nCharClassNumericType) != 0) && + ((nType & ~(nCharClassNumericTypeMask)) == 0); + } + + /// whether type is pure alphanumeric or not, e.g. return of getStringType + static inline sal_Bool isAlphaNumericType( sal_Int32 nType ) + { + return ((nType & (nCharClassAlphaType | + nCharClassNumericType)) != 0) && + ((nType & ~(nCharClassAlphaTypeMask | + nCharClassNumericTypeMask)) == 0); + } + + /// whether type is pure letter or not, e.g. return of getStringType + static inline sal_Bool isLetterType( sal_Int32 nType ) + { + return ((nType & nCharClassLetterType) != 0) && + ((nType & ~(nCharClassLetterTypeMask)) == 0); + } + + /// whether type is pure letternumeric or not, e.g. return of getStringType + static inline sal_Bool isLetterNumericType( sal_Int32 nType ) + { + return ((nType & (nCharClassLetterType | + nCharClassNumericType)) != 0) && + ((nType & ~(nCharClassLetterTypeMask | + nCharClassNumericTypeMask)) == 0); + } + + + // Wrapper implementations of class CharacterClassification + + String toUpper( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + String toLower( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + String toTitle( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + + ::rtl::OUString toUpper_rtl( const ::rtl::OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const; + ::rtl::OUString toLower_rtl( const ::rtl::OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const; + // use the postfix because compilers could get confused by the both similar versions + // (me thinks they shouldn't, but in fact MSCV 6 does) + + sal_Int16 getType( const String& rStr, xub_StrLen nPos ) const; + sal_Int16 getCharacterDirection( const String& rStr, xub_StrLen nPos ) const; + sal_Int16 getScript( const String& rStr, xub_StrLen nPos ) const; + sal_Int32 getCharacterType( const String& rStr, xub_StrLen nPos ) const; + sal_Int32 getStringType( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + + ::com::sun::star::i18n::ParseResult parseAnyToken( + const String& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const String& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const String& userDefinedCharactersCont ) const; + + ::com::sun::star::i18n::ParseResult parsePredefinedToken( + sal_Int32 nTokenType, + const String& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const String& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const String& userDefinedCharactersCont ) const; + + + // Functionality of class International methods + + sal_Bool isAlpha( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isLetter( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isDigit( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isAlphaNumeric( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isLetterNumeric( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isAlpha( const String& rStr ) const; + sal_Bool isLetter( const String& rStr ) const; + sal_Bool isNumeric( const String& rStr ) const; + sal_Bool isAlphaNumeric( const String& rStr ) const; + sal_Bool isLetterNumeric( const String& rStr ) const; + + void toUpper( String& rStr ) const + { rStr = toUpper( rStr, 0, rStr.Len() ); } + void toLower( String& rStr ) const + { rStr = toLower( rStr, 0, rStr.Len() ); } + inline String upper( const String& rStr ) const + { return toUpper( rStr, 0, rStr.Len() ); } + inline String lower( const String& rStr ) const + { return toLower( rStr, 0, rStr.Len() ); } + + const ::rtl::OUString& toUpper_rtl( ::rtl::OUString& _rStr ) const { return _rStr = toUpper_rtl( _rStr, 0, _rStr.getLength() ); } + const ::rtl::OUString& toLower_rtl( ::rtl::OUString& _rStr ) const { return _rStr = toLower_rtl( _rStr, 0, _rStr.getLength() ); } +}; + + + +#endif // _UNOTOOLS_CHARCLASS_HXX diff --git a/unotools/inc/unotools/collatorwrapper.hxx b/unotools/inc/unotools/collatorwrapper.hxx new file mode 100644 index 000000000000..7440822a1d3a --- /dev/null +++ b/unotools/inc/unotools/collatorwrapper.hxx @@ -0,0 +1,100 @@ +/************************************************************************* + * + * 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: collatorwrapper.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. + * + ************************************************************************/ +#include "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_COLLATORWRAPPER_HXX +#define _UNOTOOLS_COLLATORWRAPPER_HXX + +#ifndef _COM_SUN_STAR_UTIL_XCOLLATOR_HPP_ +#include <com/sun/star/i18n/XCollator.hpp> +#endif + +namespace com { namespace sun { namespace star { namespace lang { + class XMultiServiceFactory; +}}}} + +class UNOTOOLS_DLLPUBLIC CollatorWrapper +{ + private: + + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory + > mxServiceFactory; + + ::com::sun::star::uno::Reference< + ::com::sun::star::i18n::XCollator + > mxInternationalCollator; + + public: + + CollatorWrapper ( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > &xServiceFactoryIn); + + ~CollatorWrapper(); + + sal_Int32 + compareSubstring ( + const ::rtl::OUString& s1, sal_Int32 off1, sal_Int32 len1, + const ::rtl::OUString& s2, sal_Int32 off2, sal_Int32 len2) const; + + sal_Int32 + compareString ( + const ::rtl::OUString& s1, const ::rtl::OUString& s2) const; + + ::com::sun::star::uno::Sequence< ::rtl::OUString > + listCollatorAlgorithms ( + const ::com::sun::star::lang::Locale& rLocale) const; + + ::com::sun::star::uno::Sequence< sal_Int32 > + listCollatorOptions ( + const ::rtl::OUString& rAlgorithm) const; + + sal_Int32 + loadDefaultCollator ( + const ::com::sun::star::lang::Locale& rLocale, sal_Int32 nOption); + + sal_Int32 + loadCollatorAlgorithm ( + const ::rtl::OUString& rAlgorithm, + const ::com::sun::star::lang::Locale& rLocale, sal_Int32 nOption); + + void + loadCollatorAlgorithmWithEndUserOption ( + const ::rtl::OUString& rAlgorithm, + const ::com::sun::star::lang::Locale& rLocale, + const ::com::sun::star::uno::Sequence< sal_Int32 >& rOption); + + protected: + + CollatorWrapper(); +}; + +#endif /* _UNOTOOLS_COLLATORWRAPPER_HXX */ diff --git a/unotools/inc/unotools/componentresmodule.hxx b/unotools/inc/unotools/componentresmodule.hxx new file mode 100644 index 000000000000..59e05f085b1c --- /dev/null +++ b/unotools/inc/unotools/componentresmodule.hxx @@ -0,0 +1,206 @@ +/************************************************************************* + * + * 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: componentresmodule.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 UNOTOOLS_INC_UNOTOOLS_COMPONENTRESMODULE_HXX +#define UNOTOOLS_INC_UNOTOOLS_COMPONENTRESMODULE_HXX + +#include <comphelper/componentmodule.hxx> +#include <unotools/unotoolsdllapi.h> + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ +#include <tools/resid.hxx> + +#include <memory> + +class ResMgr; + +//........................................................................ +namespace utl +{ +//........................................................................ + + class OComponentResModuleImpl; + + //==================================================================== + //= OComponentResourceModule + //==================================================================== + /** extends the <type scope="comphelper">OModule</type> implementation with + simply resource access + */ + class UNOTOOLS_DLLPUBLIC OComponentResourceModule : public ::comphelper::OModule + { + private: + typedef ::comphelper::OModule BaseClass; + + private: + ::std::auto_ptr< OComponentResModuleImpl > m_pImpl; + + public: + OComponentResourceModule( const ::rtl::OString& _rResFilePrefix ); + ~OComponentResourceModule(); + + /// get the vcl res manager of the module + ResMgr* getResManager(); + + protected: + // OModule overridables + virtual void onFirstClient(); + virtual void onLastClient(); + }; + + //========================================================================= + //= ModuleRes + //========================================================================= + /** specialized ResId, using the ressource manager provided by a given <type>OModule</type> + */ + class UNOTOOLS_DLLPUBLIC ModuleRes : public ::ResId + { + public: + ModuleRes( USHORT _nId, OComponentResourceModule& _rModule ) : ResId( _nId, *_rModule.getResManager() ) { } + }; + + //==================================================================== + //= defining a concrete module + //==================================================================== +#define DEFINE_MODULE( ModuleClass, ClientClass, ResClass ) \ + /* -------------------------------------------------------------------- */ \ + class ModuleClass : public ::utl::OComponentResourceModule \ + { \ + friend struct CreateModuleClass; \ + typedef ::utl::OComponentResourceModule BaseClass; \ + \ + public: \ + static ModuleClass& getInstance(); \ + \ + private: \ + ModuleClass(); \ + }; \ + \ + /* -------------------------------------------------------------------- */ \ + class ClientClass : public ::comphelper::OModuleClient \ + { \ + private: \ + typedef ::comphelper::OModuleClient BaseClass; \ + \ + public: \ + ClientClass() : BaseClass( ModuleClass::getInstance() ) \ + { \ + } \ + }; \ + \ + /* -------------------------------------------------------------------- */ \ + class ResClass : public ::utl::ModuleRes \ + { \ + private: \ + typedef ::utl::ModuleRes BaseClass; \ + \ + public: \ + ResClass( USHORT _nId ) : BaseClass( _nId, 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 concrete module + //==================================================================== +#define IMPLEMENT_MODULE( ModuleClass, resprefix ) \ + struct CreateModuleClass \ + { \ + ModuleClass* operator()() \ + { \ + static ModuleClass* pModule = new ModuleClass; \ + return pModule; \ + /* yes, in theory, this is a resource leak, since the ModuleClass \ + will never be cleaned up. However, using a non-heap instance of ModuleClass \ + would not work: It would be cleaned up when the module is unloaded. \ + This might happen (and is likely to happen) *after* the tools-library \ + has been unloaded. However, the module's dtor is where we would delete \ + our resource manager (in case not all our clients de-registered) - which \ + would call into the already-unloaded tools-library. */ \ + } \ + }; \ + \ + ModuleClass::ModuleClass() \ + :BaseClass( ::rtl::OString( resprefix ) ) \ + { \ + } \ + \ + ModuleClass& ModuleClass::getInstance() \ + { \ + return *rtl_Instance< ModuleClass, CreateModuleClass, ::osl::MutexGuard, ::osl::GetGlobalMutex >:: \ + create( CreateModuleClass(), ::osl::GetGlobalMutex() ); \ + } \ + +//........................................................................ +} // namespace utl +//........................................................................ + +#endif // UNOTOOLS_INC_UNOTOOLS_COMPONENTRESMODULE_HXX + diff --git a/unotools/inc/unotools/configitem.hxx b/unotools/inc/unotools/configitem.hxx new file mode 100644 index 000000000000..f3b9db2da452 --- /dev/null +++ b/unotools/inc/unotools/configitem.hxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * 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: configitem.hxx,v $ + * $Revision: 1.26 $ + * + * 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 _UTL_CONFIGITEM_HXX_ +#define _UTL_CONFIGITEM_HXX_ + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/uno/Reference.h> +#include "unotools/unotoolsdllapi.h" + +//----------------------------------------------------------------------------- +namespace com{ namespace sun{ namespace star{ + namespace uno{ + class Any; + } + namespace beans{ + struct PropertyValue; + } + namespace container{ + class XHierarchicalNameAccess; + } + namespace util{ + class XChangesListener; + } +}}} +//----------------------------------------------------------------------------- +namespace utl +{ +#define CONFIG_MODE_IMMEDIATE_UPDATE 0x00 +#define CONFIG_MODE_DELAYED_UPDATE 0x01 +#define CONFIG_MODE_ALL_LOCALES 0x02 +#define CONFIG_MODE_RELEASE_TREE 0x04 +#define CONFIG_MODE_IGNORE_ERRORS 0x08 // prevent assertions, if creation fails +#define CONFIG_MODE_PROPAGATE_ERRORS 0x10 // throw exceptions, if creation fails + + enum ConfigNameFormat + { + CONFIG_NAME_PLAINTEXT_NAME, // unescaped local node name, for user display etc. + CONFIG_NAME_LOCAL_NAME, // local node name, for use in XNameAccess etc. ("Item", "Q & A") + CONFIG_NAME_LOCAL_PATH, // one-level relative path, for use when building pathes etc. ("Item", "Typ['Q & A']") + CONFIG_NAME_FULL_PATH, // full absolute path. ("/org.openoffice.Sample/Group/Item", "/org.openoffice.Sample/Set/Typ['Q & A']") + + CONFIG_NAME_DEFAULT = CONFIG_NAME_LOCAL_PATH // default format + }; + + class ConfigChangeListener_Impl; + class ConfigManager; + struct ConfigItem_Impl; + + class UNOTOOLS_DLLPUBLIC ConfigItem + { + friend class ConfigChangeListener_Impl; + friend class ConfigManager; + + const rtl::OUString sSubTree; + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> + m_xHierarchyAccess; + com::sun::star::uno::Reference< com::sun::star::util::XChangesListener > + xChangeLstnr; + ConfigItem_Impl* pImpl; + + ConfigItem();// + void RemoveChangesListener(); + void CallNotify( + const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); + + //*********************************************************************************************************************** + // In special mode ALL_LOCALES we must support reading/writing of localized cfg entries as Sequence< PropertyValue >. + // These methods are helper to convert given lists of names and Any-values. + // format: PropertyValue.Name = <locale as ISO string> + // PropertyValue.Value = <value; type depends from cfg entry!> + // e.g. + // LOCALIZED NODE + // "UIName" + // LOCALE VALUE + // "de" "Mein Name" + // "en-US" "my name" + void impl_packLocalizedProperties ( const com::sun::star::uno::Sequence< rtl::OUString >& lInNames , + const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lInValues , + com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lOutValues ); + void impl_unpackLocalizedProperties ( const com::sun::star::uno::Sequence< rtl::OUString >& lInNames , + const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lInValues , + com::sun::star::uno::Sequence< rtl::OUString >& lOutNames , + com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lOutValues ); + + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> + GetTree(); + + protected: + ConfigItem(const rtl::OUString rSubTree, + sal_Int16 nMode = CONFIG_MODE_DELAYED_UPDATE); + ConfigItem(utl::ConfigManager& rManager, const rtl::OUString rSubTree); + + void SetModified (); // mark item as modified + void ClearModified(); // reset state after commit! + + com::sun::star::uno::Sequence< com::sun::star::uno::Any> + GetProperties(const com::sun::star::uno::Sequence< rtl::OUString >& rNames); + + com::sun::star::uno::Sequence< sal_Bool > + GetReadOnlyStates(const com::sun::star::uno::Sequence< rtl::OUString >& rNames); + + sal_Bool PutProperties( + const com::sun::star::uno::Sequence< rtl::OUString >& rNames, + const com::sun::star::uno::Sequence< com::sun::star::uno::Any>& rValues); + + /** enables notifications about changes on selected sub nodes/values + + Before calling this method a second time for a possibly changed node/value set, + you must disable the current notifications by calling DisableNotification. + + @see Notify + @see DisableNotification + */ + sal_Bool EnableNotification(const com::sun::star::uno::Sequence< rtl::OUString >& rNames, + sal_Bool bEnableInternalNotification = sal_False); + /** disables notifications about changes on sub nodes/values, which previosly had + been enabled with EnableNotification + @see Notify + @see EnableNotification + */ + void DisableNotification(); + sal_Bool IsInternalNotification()const {return IsInValueChange();} + + //returns all members of a node in a specific format + com::sun::star::uno::Sequence< rtl::OUString > + GetNodeNames(const rtl::OUString& rNode); + //returns all members of a node in a specific format + com::sun::star::uno::Sequence< rtl::OUString > + GetNodeNames(const rtl::OUString& rNode, ConfigNameFormat eFormat); + // remove all members of a set + sal_Bool ClearNodeSet(const rtl::OUString& rNode); + // remove selected members of a set + sal_Bool ClearNodeElements(const rtl::OUString& rNode, + com::sun::star::uno::Sequence< rtl::OUString >& rElements); + // change or add members to a set + sal_Bool SetSetProperties(const rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues); + // remove, change or add members of a set + sal_Bool ReplaceSetProperties(const rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues); + // add a new node without setting any properties + sal_Bool AddNode(const rtl::OUString& rNode, const rtl::OUString& rNewNode); + + /** get a name for a new element of a set node + @param _rSetNode + relative path to the set node + @param _rBaseName + <ul><li><b>in</b>: the base to use when calculating a new name</li> + <li><b>out</b>: an unused element name</li> + </ul> + @return <TRUE/> if a free name could be generated + */ + sal_Bool getUniqueSetElementName( const rtl::OUString& _rSetNode, rtl::OUString& _rBaseName); + + public: + virtual ~ConfigItem(); + + /** is called from the ConfigManager before application ends of from the + PropertyChangeListener if the sub tree broadcasts changes. */ + virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); + + /** is called from the ConfigManager if it is destroyed before the ConfigItem. */ + void ReleaseConfigMgr(); + + /** enable locking of the XHierarchicalNameAccess if CONFIG_MODE_RELEASE_TREE is set to + prevent multiple calls ConfigManager::AcquireTree() from a single Commit() operation*/ + void LockTree(); + void UnlockTree(); + + const rtl::OUString& GetSubTreeName() const {return sSubTree;} + + sal_Bool IsModified() const; + + /** writes the changed values into the sub tree. Always called in the Dtor of the derived class. */ + virtual void Commit(); + + sal_Bool IsInValueChange() const; + + sal_Int16 GetMode() const; + + /** checks if the configuration manager used by this item is valid. + */ + sal_Bool IsValidConfigMgr() const; + }; +}//namespace utl +#endif //_UTL_CONFIGITEM_HXX_ diff --git a/unotools/inc/unotools/configmgr.hxx b/unotools/inc/unotools/configmgr.hxx new file mode 100644 index 000000000000..679e90b17249 --- /dev/null +++ b/unotools/inc/unotools/configmgr.hxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * 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: configmgr.hxx,v $ + * $Revision: 1.22.26.1 $ + * + * 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 _UTL_CONFIGMGR_HXX_ +#define _UTL_CONFIGMGR_HXX_ + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustring.hxx> +#include "unotools/unotoolsdllapi.h" + +//----------------------------------------------------------------------------- +namespace com{ namespace sun{ namespace star{ + namespace lang{ + class XMultiServiceFactory; + } + namespace container{ + class XHierarchicalNameAccess; + } +}}} + +//----------------------------------------------------------------------------- +namespace utl +{ + struct ConfigMgr_Impl; + class ConfigItem; + class UNOTOOLS_DLLPUBLIC ConfigManager + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + xConfigurationProvider; + ConfigMgr_Impl* pMgrImpl; + + static ConfigManager* pConfigManager; + static void getBasisAboutBoxProductVersion( rtl::OUString& rVersion ); + + public: + ConfigManager(); + ConfigManager(com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xConfigProvider); + ~ConfigManager(); + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + GetConfigurationProvider(); + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + GetLocalConfigurationProvider(); + + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> + AddConfigItem(utl::ConfigItem& rCfgItem); + + void RegisterConfigItem(utl::ConfigItem& rCfgItem); + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> + AcquireTree(utl::ConfigItem& rCfgItem); + + + void RemoveConfigItem(utl::ConfigItem& rCfgItem); + + void StoreConfigItems(); + + static ConfigManager* GetConfigManager(); + static void RemoveConfigManager(); + static rtl::OUString GetConfigBaseURL(); + + enum ConfigProperty + { + INSTALLPATH, // deprecated. don't use + LOCALE, + OFFICEINSTALL, // deprecated. don't use + USERINSTALLURL, // deprecated. don't use + OFFICEINSTALLURL, // deprecated. don't use + PRODUCTNAME, + PRODUCTVERSION, + PRODUCTEXTENSION, + DEFAULTCURRENCY, + PRODUCTXMLFILEFORMATNAME, + PRODUCTXMLFILEFORMATVERSION, + WRITERCOMPATIBILITYVERSIONOOO11, + OPENSOURCECONTEXT, + ABOUTBOXPRODUCTVERSION + }; + //direct readonly access to some special configuration elements + static com::sun::star::uno::Any GetDirectConfigProperty(ConfigProperty eProp); + + sal_Bool IsLocalConfigProvider(); + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> + GetHierarchyAccess(const rtl::OUString& rFullPath); + com::sun::star::uno::Any GetLocalProperty(const rtl::OUString& rProperty); + void PutLocalProperty(const rtl::OUString& , const com::sun::star::uno::Any& rValue); + + }; +}//namespace utl +#endif //_UTL_CONFIGMGR_HXX_ diff --git a/unotools/inc/unotools/confignode.hxx b/unotools/inc/unotools/confignode.hxx new file mode 100644 index 000000000000..580274004e1a --- /dev/null +++ b/unotools/inc/unotools/confignode.hxx @@ -0,0 +1,340 @@ +/************************************************************************* + * + * 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: confignode.hxx,v $ + * $Revision: 1.10 $ + * + * 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 _UNOTOOLS_CONFIGNODE_HXX_ +#define _UNOTOOLS_CONFIGNODE_HXX_ + +#include "unotools/unotoolsdllapi.h" +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> +#include <unotools/eventlisteneradapter.hxx> + +//........................................................................ +namespace utl +{ +//........................................................................ + + //======================================================================== + //= OConfigurationNode + //======================================================================== + class OConfigurationTreeRoot; + /** a small wrapper around a configuration node.<p/> + Nodes in the terminology used herein are <em>inner</em> nodes of a configuration + tree, which means <em>no leafs</em>. + */ + class UNOTOOLS_DLLPUBLIC OConfigurationNode : public ::utl::OEventListenerAdapter + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess > + m_xHierarchyAccess; /// accessing children grandchildren (mandatory interface of our UNO object) + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + m_xDirectAccess; /// accessing children (mandatory interface of our UNO object) + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > + m_xReplaceAccess; /// replacing child values + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > + m_xContainerAccess; /// modifying set nodes (optional interface of our UNO object) + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xProvider; /// the configuration provider which supplied the nodes of the hierarchy we're a part of + sal_Bool m_bEscapeNames; /// escape names before accessing children ? + + ::rtl::OUString + m_sCompletePath; + + OConfigurationNode insertNode(const ::rtl::OUString& _rName,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xNode) const throw(); + protected: + /// constructs a node object with an interface representing a node + OConfigurationNode( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxNode, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxProvider); + + public: + /// constructs an empty and invalid node object + OConfigurationNode() :m_bEscapeNames(sal_False) { } + /// copy ctor + OConfigurationNode(const OConfigurationNode& _rSource); + + /// assigment + const OConfigurationNode& operator=(const OConfigurationNode& _rSource); + + /// dtor + ~OConfigurationNode() {} + + /** open a sub node + @param _rPath access path of the to-be-opened sub node. May be a hierarchical path. + */ + OConfigurationNode openNode(const ::rtl::OUString& _rPath) const throw(); + + OConfigurationNode openNode( const sal_Char* _pAsciiPath ) const + { + return openNode( ::rtl::OUString::createFromAscii( _pAsciiPath ) ); + } + + /** create a new child node + + If the object represents a set node, this method may be used to create a new child. For non-set-nodes, the + method will fail.<br/> + Unless the respective operations on the pure configuration API, the to-be-created node immediately + becomes a part of it's hierarchy, no explicit insertion is necessary. + @param _rName name for the new child. Must be level-1-depth. + */ + OConfigurationNode createNode(const ::rtl::OUString& _rName) const throw(); + + OConfigurationNode createNode( const sal_Char* _pAsciiName ) const + { + return createNode( ::rtl::OUString::createFromAscii( _pAsciiName ) ); + } + + /** appends a node under a new name + + If the object represents a set node, this method may be used to create a new child. For non-set-nodes, the + method will fail.<br/> + Unless the respective operations on the pure configuration API, the to-be-created node immediately + becomes a part of it's hierarchy, no explicit insertion is necessary. + @param _rName name for the new child. Must be level-1-depth. + @param _aNewNode the node which should be appended + */ + OConfigurationNode appendNode(const ::rtl::OUString& _rName,const OConfigurationNode& _aNewNode) const throw(); + + OConfigurationNode appendNode( const sal_Char* _pAsciiName, const OConfigurationNode& _aNewNode ) const + { + return appendNode( ::rtl::OUString::createFromAscii( _pAsciiName ), _aNewNode ); + } + + /** remove an existent child nod + + If the object represents a set node, this method may be used to delete an existent child. For non-set-nodes, + the method will fail. + */ + sal_Bool removeNode(const ::rtl::OUString& _rName) const throw(); + + sal_Bool removeNode( const sal_Char* _pAsciiName ) const + { + return removeNode( ::rtl::OUString::createFromAscii( _pAsciiName ) ); + } + + /** retrieves the content of a descendant + + the returned value may contain anything from an interface (if <arg>_rPath</arg> refers to inner node of + the configuration tree) to any explicit value (e.g. string, integer) or even void.<br/> + Unfortunately, this implies that if a void value is returned, you won't have a clue if this means + "the path does not exist" (besides the assertion made :), or if the value is really void. + */ + ::com::sun::star::uno::Any + getNodeValue(const ::rtl::OUString& _rPath) const throw(); + + ::com::sun::star::uno::Any + getNodeValue( const sal_Char* _pAsciiPath ) const + { + return getNodeValue( ::rtl::OUString::createFromAscii( _pAsciiPath ) ); + } + + /** write a node value<p/> + The value given is written into the node specified by the given relative path.<br/> + In opposite to <method>getNodeValue</method>, _rName must refer to a leaf in the configuration tree, not an inner + node. + @return sal_True if and only if the write was successfull. + */ + sal_Bool setNodeValue(const ::rtl::OUString& _rPath, const ::com::sun::star::uno::Any& _rValue) const throw(); + + sal_Bool setNodeValue( const sal_Char* _pAsciiPath, const ::com::sun::star::uno::Any& _rValue ) const + { + return setNodeValue( ::rtl::OUString::createFromAscii( _pAsciiPath ), _rValue ); + } + + /// return the names of the existing children + ::com::sun::star::uno::Sequence< ::rtl::OUString > + getNodeNames() const throw(); + + /** enables or disables name escaping when accessing direct children<p/> + Escaping is disabled by default, usually you enable it for set nodes (e.g. with calling setEscape(isSetNode)). + Once escaping is enabled, you should not access indirect children (e.g. openNode("child/grandchild"), 'cause + escaping for such names may not be supported by the underlying API objects. + @see getEscape + */ + void setEscape(sal_Bool _bEnable = sal_True); + /** get the flag specifying the current escape behaviour + @see setEscape + */ + sal_Bool getEscape() const { return m_bEscapeNames; } + + /** clone the object, creating a new hierarchy where the root represents the same node as the object + where this method is called does.<p/> + The new hierarchy does not share any updates with the one the object is a part of, i.e. any changes made + in the existing hierarchy are not visible to the newly created one until committed (and vice versa). + @param _rRoot out parameter. upon return, contains the object representing the root of the new hierarchy. + */ + OConfigurationTreeRoot cloneAsRoot() const throw(); + + /// invalidate the object + virtual void clear() throw(); + + // ----------------------- + // meta informations about the node + + /// checks whether or not the object represents a set node. + sal_Bool isSetNode() const; + + /// checks whether or not a direct child with a given name exists + sal_Bool hasByName(const ::rtl::OUString& _rName) const throw(); + sal_Bool hasByName( const sal_Char* _pAsciiName ) const { return hasByName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); } + + /// checks whether or not a descendent (no matter if direct or indirect) with the given name exists + sal_Bool hasByHierarchicalName( const ::rtl::OUString& _rName ) const throw(); + sal_Bool hasByHierarchicalName( const sal_Char* _pAsciiName ) const { return hasByHierarchicalName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); } + + /// check if the objects represents a valid configuration node + sal_Bool isValid() const { return m_xHierarchyAccess.is(); } + + /// check whether the object is read-only of updatable + sal_Bool isReadonly() const { return !m_xReplaceAccess.is(); } + + protected: + // OEventListenerAdapter + virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ); + + protected: + enum NAMEORIGIN + { + NO_CONFIGURATION, /// the name came from a configuration node + NO_CALLER /// the name came from a client of this class + }; + ::rtl::OUString normalizeName(const ::rtl::OUString& _rName, NAMEORIGIN _eOrigin) const; + }; + + //======================================================================== + //= OConfigurationTreeRoot + //======================================================================== + /** a specialized version of a OConfigurationNode, representing the root + of a configuration sub tree<p/> + Only this class is able to commit any changes made any any OConfigurationNode + objects. + */ + class UNOTOOLS_DLLPUBLIC OConfigurationTreeRoot : public OConfigurationNode + { + ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch > + m_xCommitter; + protected: + /** ctor<p/> + */ + OConfigurationTreeRoot( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch >& _rxRootNode, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxProvider); + + /** ctor for a readonly node + */ + OConfigurationTreeRoot( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxRootNode, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxProvider); + + public: + /// modes to used when creating a top-level node object + enum CREATION_MODE + { + CM_READONLY, /// open the node (i.e. sub tree) for read access only + CM_UPDATABLE, /// open the node (i.e. sub tree) for read and write access + CM_PREFER_UPDATABLE /// open the node (i.e. sub tree) for read and write access, if this fails, open it for read acces + }; + + public: + /** default ctor<p/> + The object constructed here is invalid (i.e. <method>isValid</method> will return sal_False). + */ + OConfigurationTreeRoot() :OConfigurationNode() { } + + /// copy ctor + OConfigurationTreeRoot(const OConfigurationTreeRoot& _rSource) + :OConfigurationNode(_rSource), m_xCommitter(_rSource.m_xCommitter) { } + + /** open a new top-level configuration node + + opens a new node which is the root if an own configuration sub tree. This is what "top level" means: The + node does not have a parent. It does not mean that the node represents a module tree (like org.openoffice.Office.Writer + or such).<br/> + In opposite to <method>createWithServiceFactory</method>, createWithProvider expects a configuration provider + to work with. + + @param _rxConfProvider configuration provider to use when retrieving the node. + @param _rPath path to the node the object should represent + @param _nDepth depth for node retrieval + @param _eMode specifies which privileges should be applied when retrieving the node + + @see createWithServiceFactory + */ + static OConfigurationTreeRoot createWithProvider( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxConfProvider, + const ::rtl::OUString& _rPath, + sal_Int32 _nDepth = -1, + CREATION_MODE _eMode = CM_PREFER_UPDATABLE, + sal_Bool _bLazyWrite = sal_True + ); + + /** open a new top-level configuration node<p/> + opens a new node which is the root if an own configuration sub tree. This is what "top level" means: The + node does not have a parent. It does not mean that the node represents a module tree (like org.openoffice.Office.Writer + or such).<br/> + In opposite to <method>createWithProvider</method>, createWithProvider expects a service factory. This factory + is used to create a configuration provider, and this provider is used to retrieve the node + @see createWithProvider + @param _rxORB service factory to use to create the configuration provider. + @param _rPath path to the node the object should represent + @param _nDepth depth for node retrieval + @param _eMode specifies which privileges should be applied when retrieving the node + */ + static OConfigurationTreeRoot createWithServiceFactory(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_PREFER_UPDATABLE, sal_Bool _bLazyWrite = sal_True); + + /** tolerant version of the <member>createWithServiceFactory</member> + + <p>No assertions are thrown in case of an failure to initialize the configuration service, but once + the configuration could be initialized, errors in the creation of the specific node (e.g. because the + given node path does not exist) are still asserted.</p> + */ + static OConfigurationTreeRoot tryCreateWithServiceFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_PREFER_UPDATABLE, sal_Bool _bLazyWrite = sal_True ); + + /** commit all changes made on the subtree the object is the root for<p/> + All changes made on any <type>OConfigurationNode</type> object retrieved (maybe indirect) from this root + object are committed when calling this method. + @return sal_True if and only if the commit was successfull + */ + sal_Bool commit() const throw(); + + /// invalidate the object + virtual void clear() throw(); + }; + +//........................................................................ +} // namespace utl +//........................................................................ + +#endif // _UNOTOOLS_CONFIGNODE_HXX_ + diff --git a/unotools/inc/unotools/configpathes.hxx b/unotools/inc/unotools/configpathes.hxx new file mode 100644 index 000000000000..081021145055 --- /dev/null +++ b/unotools/inc/unotools/configpathes.hxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * 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: configpathes.hxx,v $ + * $Revision: 1.5.22.1 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef UNOTOOLS_CONFIGPATHES_HXX_INCLUDED +#define UNOTOOLS_CONFIGPATHES_HXX_INCLUDED +#include <sal/types.h> + +namespace rtl +{ + class OUString; +} + +//---------------------------------------------------------------------------- +namespace utl +{ +//---------------------------------------------------------------------------- + /** extract the local nodename and the parent nodepath + from a configuration path. + + @param _sInPath + A configuration path that is not an empty or root path.<BR/> + If this is not a valid configuration path, it is interpreted as + local name of a node. + + @param _rsOutPath + On exit: The configuration path obtained by dropping + the last level off <var>_sInPath</var>.<BR/> + If <var>_sInPath</var> could not be parsed as a valid + configuration path, this is set to an empty string. + + @param _rsLocalName + On exit: The plain (non-escaped) name of the node identified by + <var>_sInPath</var>. <BR/> + If <var>_sInPath</var> could not be parsed as a valid + configuration path, this is set to <var>_sInPath</var>. + + @returns + <TRUE/>, if a parent path could be set + <FALSE/>, if the path was a one-level path or an invalid path + + */ + UNOTOOLS_DLLPUBLIC sal_Bool splitLastFromConfigurationPath(::rtl::OUString const& _sInPath, + ::rtl::OUString& _rsOutPath, + ::rtl::OUString& _rsLocalName); + +//---------------------------------------------------------------------------- + /** extract the first nodename from a configuration path. + + @param _sInPath + A relative configuration path that is not empty.<BR/> + If this is not a valid configuration path, it is interpreted as + a single name of a node. + + @returns + The plain (non-escaped) name of the node that is the first step + when traversing <var>_sInPath</var>.<BR/> + If <var>_sInPath</var> could not be parsed as a valid + configuration path, it is returned unaltered. + + */ + UNOTOOLS_DLLPUBLIC ::rtl::OUString extractFirstFromConfigurationPath(::rtl::OUString const& _sInPath); + +//---------------------------------------------------------------------------- + /** check whether a path is to a nested node with respect to a parent path. + + @param _sNestedPath + A configuration path that maybe points to a descendant of the node + identified by <var>_sPrefixPath</var>, with both pathes starting + from the same node (or both being absolute). + + @param _sPrefixPath + A configuration path.<BR/> + If this path is absolute, <var>_sNestedPath</var> should be absolute; + If this path is relative, <var>_sNestedPath</var> should be relative; + If this path is empty, <var>_sNestedPath</var> may start with a '/', + which is disregarded. + + @returns + <TRUE/>, if <var>_sPrefixPath</var> is a prefix of <var>_sNestedPath</var>; + <FALSE/> otherwise.<BR/> + If both pathes are equal <TRUE/> is returned. + + */ + sal_Bool isPrefixOfConfigurationPath(::rtl::OUString const& _sNestedPath, + ::rtl::OUString const& _sPrefixPath); + +//---------------------------------------------------------------------------- + /** get the relative path to a nested node with respect to a parent path. + + @param _sNestedPath + A configuration path that points to a descendant of the node + identified by <var>_sPrefixPath</var>, with both pathes starting + from the same node (or both being absolute). + + @param _sPrefixPath + A configuration path.<BR/> + If this path is absolute, <var>_sNestedPath</var> must be absolute; + If this path is relative, <var>_sNestedPath</var> must be relative; + If this path is empty, <var>_sNestedPath</var> may start with a '/', + which is stripped. + + @returns + The remaining relative path from the target of <var>_sPrefixPath</var> + to the target of <var>_sNestedPath</var>.<BR/> + If <var>_sPrefixPath</var> is not a prefix of <var>_sNestedPath</var>, + <var>_sNestedPath</var> is returned unaltered. + + */ + UNOTOOLS_DLLPUBLIC ::rtl::OUString dropPrefixFromConfigurationPath(::rtl::OUString const& _sNestedPath, + ::rtl::OUString const& _sPrefixPath); + +//---------------------------------------------------------------------------- + /** Create a one-level relative configuration path from a set element name + without a known set element type. + + @param _sElementName + An arbitrary string that is to be interpreted as + name of a configuration set element. + + @returns + A one-level relative path to the element, of the form + "*['<Name>']", where <Name> is properly escaped. + + */ + UNOTOOLS_DLLPUBLIC ::rtl::OUString wrapConfigurationElementName(::rtl::OUString const& _sElementName); + +//---------------------------------------------------------------------------- + /** Create a one-level relative configuration path from a set element name + and a known set element type. + + @param _sElementName + An arbitrary string that is to be interpreted as + name of a configuration set element. + + @param _sTypeName + An string identifying the type of the element. Usually this is be + the name of the element-template of the set.<BR/> + + @returns + A one-level relative path to the element, of the form + "<Type>['<Name>']", where <Name> is properly escaped. + + */ + ::rtl::OUString wrapConfigurationElementName(::rtl::OUString const& _sElementName, + ::rtl::OUString const& _sTypeName); + +//---------------------------------------------------------------------------- +} // namespace utl +//---------------------------------------------------------------------------- + +#endif // UNOTOOLS_CONFIGPATHES_HXX_INCLUDED + diff --git a/unotools/inc/unotools/configvaluecontainer.hxx b/unotools/inc/unotools/configvaluecontainer.hxx new file mode 100644 index 000000000000..d4442d6bde6a --- /dev/null +++ b/unotools/inc/unotools/configvaluecontainer.hxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * 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: configvaluecontainer.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. + * + ************************************************************************/ +#include "unotools/unotoolsdllapi.h" + +#ifndef UNOTOOLS_CONFIGVALUECONTAINER_HXX +#define UNOTOOLS_CONFIGVALUECONTAINER_HXX +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <osl/mutex.hxx> + +//......................................................................... +namespace utl +{ +//......................................................................... + +#define CVC_READONLY_ACCESS 0x0000 +#define CVC_UPDATE_ACCESS 0x0001 + +#define CVC_LAZY_UPDATE 0x0000 +#define CVC_IMMEDIATE_UPDATE 0x0002 + + struct OConfigurationValueContainerImpl; + struct NodeValueAccessor; + //===================================================================== + //= OConfigurationValueContainer + //===================================================================== + /** allows simple access to static configuration structures. + + <p>The basic idea of this class is that it's clients (usually derived classes) simply register an + address in memory and a node path, and upon explicit request, the configuration value and the memory + are syncronized.<br/> + This means that when calling <method>read</method>, the current configuration values are copied into + the memory registered for them, and upon calling <method>write</method> the current values in memory + are set in the configuration nodes.</p> + + <p>This way, the usage of this class is pretty straight forward: derive your own class, spend some members + to it, and bind these members to configuration node (usually done in the ctor of the derived class).<br/> + In the dtor, simply call <method>write</method> and <method>commit</method>.</p> + + <p>There is no auto-commit mechanism in the dtor: In the usual scenario, when you derive from this class + and bind some members of your derived class to config nodes, this means that your members will be destroyed + before your base class' dtor is called, so accessing the memory during such a theoretical auto-commit would + yield undefined behaviour.</p> + */ + class UNOTOOLS_DLLPUBLIC OConfigurationValueContainer + { + private: + OConfigurationValueContainerImpl* + m_pImpl; + + protected: + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& + getServiceFactory( ) const; + + protected: + //----------------------------------------------------------------- + // construction/destruction + + /** constructs the object + + @param _rxORB + specifies the service factory which should be used to access the configuration + @param _rAccessSafety + As this class is intented to manipulate objects it does not hold itself (see the various + registerXXX methods), it needs to guard these access for muti threading safety.<br/> + The mutex given here is locked whenever such an access occurs. + @param _pConfigLocation + is an ASCII string describing the configurations node path + @param _nAccessFlags + specifies different aspects of the configuration aspect to be created, e.g. it's update mode etc.<br/> + See the CVC_xxx constants for what you can use here. + @param _nLevels + specifies the number of levels to access under the node given by <arg>_pConfigLocation</arg> + */ + OConfigurationValueContainer( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + ::osl::Mutex& _rAccessSafety, + const sal_Char* _pConfigLocation, + const sal_uInt16 _nAccessFlags = CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, + const sal_Int32 _nLevels = -1 + ); + + /** constructs the object + + @param _rxORB + specifies the service factory which should be used to access the configuration + @param _rAccessSafety + As this class is intented to manipulate objects it does not hold itself (see the various + registerXXX methods), it needs to guard these access for muti threading safety.<br/> + The mutex given here is locked whenever such an access occurs. + @param _rConfigLocation + describes the configurations node path + @param _nAccessFlags + specifies different aspects of the configuration aspect to be created, e.g. it's update mode etc.<br/> + See the CVC_xxx constants for what you can use here. + @param _nLevels + specifies the number of levels to access under the node given by <arg>_pConfigLocation</arg> + */ + OConfigurationValueContainer( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + ::osl::Mutex& _rAccessSafety, + const ::rtl::OUString& _rConfigLocation, + const sal_uInt16 _nAccessFlags = CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, + const sal_Int32 _nLevels = -1 + ); + + /// dtor + ~OConfigurationValueContainer(); + + //----------------------------------------------------------------- + // registering data containers + + /** registers a data accessor of an arbitrary type. + + <p>Usually, in your derived class you simply add a member of the correct type of the configuration + value, and then call this method with the address of this member.</p> + + <p>If the value you want to access may be <NULL/> at runtime, and if you want to recognize such + <NULL/> values, you may consider using <method>registerNullValueExchangeLocation</method>.</p> + + @param _pRelativePathAscii + is a relative (ASCII) path of the node which should be "mirrored" into the accessor. + @param _pContainer + points to the accessors location in memory. Usually, this is simply an address of your derived class + @param _rValueType + is the type of your accessort. This type must be supported by the configuration. + */ + void registerExchangeLocation( + const sal_Char* _pRelativePathAscii, + void* _pContainer, + const ::com::sun::star::uno::Type& _rValueType + ); + + /** registers a data accessor of an arbitrary type. + + <p>Usually, in your derived class you simply add a member of type <type scope="com.sun.star.uno">Any</type>, + and then call this method with the address of this member.</p> + + @param _pRelativePathAscii + is a relative (ASCII) path of the node which should be "mirrored" into the accessor. + @param _pContainer + points to the Any you want to hold the value + */ + void registerNullValueExchangeLocation( + const sal_Char* _pRelativePathAscii, + ::com::sun::star::uno::Any* _pContainer + ); + + public: + /** reads the configuration data + + <p>The current values of the nodes bound (using the registerXXX methods) is copied into their + respective exchange locations.</p> + + <p>Please note that any changes done to your exchange locations are overridden with the current config + values.</p> + + @see write + */ + void read( ); + + /** updates the configuration data + + <p>The current values in memory (your exchange locations registered using the registerXXX methods) is + forwarded to their respective configuration nodes.</p> + + <p>Note that calling <method>write</method>(<TRUE/) is the same as calling <method>commit</method>(<TRUE/>).</p> + + @precond + The access must have been created for update access + + @param _bCommit + If set to <TRUE/>, an automatic commit is done after the values have been synchronized.<br/> + If set to <FALSE/>, you must explicitly call <method>commit</method> to make your changes persistent. + + @see read + @see commit + */ + void write( sal_Bool _bCommit = sal_True ); + + /** commits any changes done + + <p>Note that calling <method>write</method>(<TRUE/) is the same as calling <method>commit</method>(<TRUE/>).</p> + + @precond + The access must have been created for update access + + @param _bWrite + If <TRUE/>, the current values in the exchange locations are written to the configuration nodes + before the changes are committed.<br/> + If <FALSE/>, only the current values in the config nodes (as present since the last call to + <method>write</method>) are committed. + */ + void commit( sal_Bool _bWrite = sal_True ); + + private: + /// implements the ctors + void implConstruct( + const ::rtl::OUString& _rConfigLocation, + const sal_uInt16 _nAccessFlags, + const sal_Int32 _nLevels + ); + + /// registers a value container + void implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor ); + }; + +//......................................................................... +} // namespace utl +//......................................................................... + +#endif // UNOTOOLS_CONFIGVALUECONTAINER_HXX + diff --git a/unotools/inc/unotools/datetime.hxx b/unotools/inc/unotools/datetime.hxx new file mode 100644 index 000000000000..aaccfc29eb0f --- /dev/null +++ b/unotools/inc/unotools/datetime.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * 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: datetime.hxx,v $ + * $Revision: 1.6 $ + * + * 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. + * + ************************************************************************/ + +//= conversions UNO3.TimeClass <-> Tools.TimeClass (Date/Time/DateTime) +#include "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_DATETIME_HXX_ +#define _UNOTOOLS_DATETIME_HXX_ + +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/util/Time.hpp> +#include <com/sun/star/util/DateTime.hpp> + +class Date; +class Time; +class DateTime; + +//......................................................................... +namespace utl +{ +//......................................................................... + + namespace starutil = ::com::sun::star::util; + + UNOTOOLS_DLLPUBLIC void typeConvert(const Time& _rTime, starutil::Time& _rOut); + UNOTOOLS_DLLPUBLIC void typeConvert(const starutil::Time& _rTime, Time& _rOut); + + UNOTOOLS_DLLPUBLIC void typeConvert(const Date& _rDate, starutil::Date& _rOut); + UNOTOOLS_DLLPUBLIC void typeConvert(const starutil::Date& _rDate, Date& _rOut); + + UNOTOOLS_DLLPUBLIC void typeConvert(const DateTime& _rDateTime, starutil::DateTime& _rOut); + UNOTOOLS_DLLPUBLIC void typeConvert(const starutil::DateTime& _rDateTime, DateTime& _rOut); + +//......................................................................... +} // namespace utl +//......................................................................... + +#endif // _UNOTOOLS_DATETIME_HXX_ + diff --git a/unotools/inc/unotools/desktopterminationobserver.hxx b/unotools/inc/unotools/desktopterminationobserver.hxx new file mode 100644 index 000000000000..effa35a9e293 --- /dev/null +++ b/unotools/inc/unotools/desktopterminationobserver.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * 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: desktopterminationobserver.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. + * + ************************************************************************/ +#include "unotools/unotoolsdllapi.h" + +#ifndef UNOTOOLS_INC_UNOTOOLS_DESKTOPTERMINATIONOBSERVER_HXX +#define UNOTOOLS_INC_UNOTOOLS_DESKTOPTERMINATIONOBSERVER_HXX + +/** === begin UNO includes === **/ +/** === end UNO includes === **/ + +//........................................................................ +namespace utl +{ +//........................................................................ + + //==================================================================== + //= ITerminationListener + //==================================================================== + /** non-UNO version of the <type scope="com.sun.star.frame">XTerminateListener</type> + */ + class ITerminationListener + { + public: + virtual bool queryTermination() const = 0; + virtual void notifyTermination() = 0; + }; + + //==================================================================== + //= DesktopTerminationObserver + //==================================================================== + /** a class which allows non-UNO components to observe the desktop (aka application) + for it's shutdown + */ + class UNOTOOLS_DLLPUBLIC DesktopTerminationObserver + { + public: + /** registers a listener which should be notified when the desktop terminates + (which means the application is shutting down) + */ + static void registerTerminationListener( ITerminationListener* _pListener ); + + /** revokes a termination listener + */ + static void revokeTerminationListener( ITerminationListener* _pListener ); + + private: + DesktopTerminationObserver(); // never implemented, only static methods + }; + +//........................................................................ +} // namespace utl +//........................................................................ + +#endif // UNOTOOLS_INC_UNOTOOLS_DESKTOPTERMINATIONOBSERVER_HXX + diff --git a/unotools/inc/unotools/digitgroupingiterator.hxx b/unotools/inc/unotools/digitgroupingiterator.hxx new file mode 100644 index 000000000000..5525e01bb297 --- /dev/null +++ b/unotools/inc/unotools/digitgroupingiterator.hxx @@ -0,0 +1,207 @@ +/************************************************************************* + * + * 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: digitgroupingiterator.hxx,v $ + * $Revision: 1.3 $ + * + * 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_UNOTOOLS_DIGITGROUPINGITERATOR_HXX +#define INCLUDED_UNOTOOLS_DIGITGROUPINGITERATOR_HXX + +#include <com/sun/star/uno/Sequence.hxx> + +namespace utl { + +/** Iterator to be used with a digit grouping as obtained through + LocaleDataWrapper::getDigitGrouping(). + + The iterator advances over the digit groupings, returning the number of + digits per group. If the last group was encountered the iterator will + always return the last grouping. + + Grouping values are sanitized to be 0 <= value <= SAL_MAX_UINT16, even if + originally Int32, to be able to easily cast it down to String's xub_StrLen. + This shouldn't make any difference in practice. + + Usage example with a string buffer containing a decimal representation of + an integer number. Note that of course this loop could be optimized to not + count single characters but hunks of groups instead using the get() method, + this is just for illustrating usage. Anyway, for double values it is highly + more efficient to use ::rtl::math::doubleToString() and pass the grouping + sequence, instead of using this iterator and inserting charcters into + strings. + + DigitGroupingIterator aGrouping(...) + sal_Int32 nCount = 0; + sal_Int32 n = aBuffer.getLength(); + // >1 because we don't want to insert a separator if there is no leading digit. + while (n-- > 1) + { + if (++nCount >= aGrouping.getPos()) + { + aBuffer.insert( n, cSeparator); + nGroupDigits = aGrouping.advance(); + } + } + + */ + +class DigitGroupingIterator +{ + const ::com::sun::star::uno::Sequence< sal_Int32 > maGroupings; + + sal_Int32 mnGroup; // current active grouping + sal_Int32 mnDigits; // current active digits per group + sal_Int32 mnNextPos; // position (in digits) of next grouping + + void setInfinite() + { + mnGroup = maGroupings.getLength(); + } + + bool isInfinite() const + { + return mnGroup >= maGroupings.getLength(); + } + + sal_Int32 getGrouping() const + { + if (mnGroup < maGroupings.getLength()) + { + sal_Int32 n = maGroupings[mnGroup]; + OSL_ENSURE( 0 <= n && n <= SAL_MAX_UINT16, "DigitGroupingIterator::getGrouping: far out"); + if (n < 0) + n = 0; // sanitize ... + else if (n > SAL_MAX_UINT16) + n = SAL_MAX_UINT16; // limit for use with xub_StrLen + return n; + } + return 0; + } + + void setPos() + { + // someone might be playing jokes on us, so check for overflow + if (mnNextPos <= SAL_MAX_INT32 - mnDigits) + mnNextPos += mnDigits; + } + + void setDigits() + { + sal_Int32 nPrev = mnDigits; + mnDigits = getGrouping(); + if (!mnDigits) + { + mnDigits = nPrev; + setInfinite(); + } + setPos(); + } + + void initGrouping() + { + mnDigits = 3; // just in case of constructed with empty grouping + mnGroup = 0; + mnNextPos = 0; + setDigits(); + } + + // not implemented, prevent usage + DigitGroupingIterator(); + DigitGroupingIterator( const DigitGroupingIterator & ); + DigitGroupingIterator & operator=( const DigitGroupingIterator & ); + +public: + + explicit DigitGroupingIterator( const ::com::sun::star::uno::Sequence< sal_Int32 > & rGroupings ) + : maGroupings( rGroupings) + { + initGrouping(); + } + + /** Advance iterator to next grouping. */ + DigitGroupingIterator & advance() + { + if (isInfinite()) + setPos(); + else + { + ++mnGroup; + setDigits(); + } + return *this; + } + + /** Obtain current grouping. Always > 0. */ + sal_Int32 get() const + { + return mnDigits; + } + + /** The next position (in integer digits) from the right where to insert a + group separator. */ + sal_Int32 getPos() + { + return mnNextPos; + } + + /** Reset iterator to start again from the right beginning. */ + void reset() + { + initGrouping(); + } + + /** Create a sequence of bool values containing positions where to add a + separator when iterating forward over a string and copying digit per + digit. For example, for grouping in thousands and nIntegerDigits==7 the + sequence returned would be {1,0,0,1,0,0,0} so the caller would add a + separator after the 1st and the 4th digit. */ + static ::com::sun::star::uno::Sequence< sal_Bool > createForwardSequence( + sal_Int32 nIntegerDigits, + const ::com::sun::star::uno::Sequence< sal_Int32 > & rGroupings ) + { + if (nIntegerDigits <= 0) + return ::com::sun::star::uno::Sequence< sal_Bool >(); + DigitGroupingIterator aIterator( rGroupings); + ::com::sun::star::uno::Sequence< sal_Bool > aSeq( nIntegerDigits); + sal_Bool* pArr = aSeq.getArray(); + for (sal_Int32 j = 0; --nIntegerDigits >= 0; ++j) + { + if (j == aIterator.getPos()) + { + pArr[nIntegerDigits] = sal_True; + aIterator.advance(); + } + else + pArr[nIntegerDigits] = sal_False; + } + return aSeq; + } +}; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_DIGITGROUPINGITERATOR_HXX diff --git a/unotools/inc/unotools/docinfohelper.hxx b/unotools/inc/unotools/docinfohelper.hxx new file mode 100644 index 000000000000..80534af1430e --- /dev/null +++ b/unotools/inc/unotools/docinfohelper.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * 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: docinfohelper.hxx,v $ + * $Revision: 1.3 $ + * + * 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 _UNOTOOLS_DOCINFOHELPER_HXX_ +#define _UNOTOOLS_DOCINFOHELPER_HXX_ + +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> + +namespace utl +{ +class UNOTOOLS_DLLPUBLIC DocInfoHelper +{ +public: + static ::rtl::OUString GetGeneratorString(); + +}; + +} // namespace utl + + +#endif // _UNOTOOLS_DOCINFOHELPER_HXX_ + diff --git a/unotools/inc/unotools/eventlisteneradapter.hxx b/unotools/inc/unotools/eventlisteneradapter.hxx new file mode 100644 index 000000000000..9bd8586034bf --- /dev/null +++ b/unotools/inc/unotools/eventlisteneradapter.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * 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: eventlisteneradapter.hxx,v $ + * $Revision: 1.6 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_EVENTLISTENERADAPTER_HXX_ +#define _UNOTOOLS_EVENTLISTENERADAPTER_HXX_ +#include <com/sun/star/lang/XComponent.hpp> + +//......................................................................... +namespace utl +{ +//......................................................................... + + struct OEventListenerAdapterImpl; + //===================================================================== + //= OEventListenerAdapter + //===================================================================== + /** base class for non-UNO dispose listeners + */ + class UNOTOOLS_DLLPUBLIC OEventListenerAdapter + { + friend class OEventListenerImpl; + + private: + UNOTOOLS_DLLPRIVATE OEventListenerAdapter( const OEventListenerAdapter& _rSource ); // never implemented + UNOTOOLS_DLLPRIVATE const OEventListenerAdapter& operator=( const OEventListenerAdapter& _rSource ); // never implemented + + protected: + OEventListenerAdapterImpl* m_pImpl; + + protected: + OEventListenerAdapter(); + virtual ~OEventListenerAdapter(); + + void startComponentListening( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp ); + void stopComponentListening( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp ); + void stopAllComponentListening( ); + + virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ) = 0; + }; + +//......................................................................... +} // namespace utl +//......................................................................... + +#endif // _UNOTOOLS_EVENTLISTENERADAPTER_HXX_ + diff --git a/unotools/inc/unotools/idhelper.hxx b/unotools/inc/unotools/idhelper.hxx new file mode 100644 index 000000000000..a2aa28d26c1b --- /dev/null +++ b/unotools/inc/unotools/idhelper.hxx @@ -0,0 +1,213 @@ +/************************************************************************* + * + * 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: idhelper.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 _UNOTOOLS_ID_HELPER_HXX_ +#define _UNOTOOLS_ID_HELPER_HXX_ + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <osl/mutex.hxx> +#include <comphelper/stl_types.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <tools/debug.hxx> + +//......................................................................... +namespace utl +{ +//......................................................................... + +//========================================================================= +// to shorten some lines ... +typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > TypeSequence; + +// compare to Sequences of Types +struct TypeSequenceLess : public ::std::binary_function<TypeSequence, TypeSequence, bool> +{ +public: + inline bool operator() (const TypeSequence& lhs, const TypeSequence& rhs) const + { + sal_Int32 nLengthLeft = lhs.getLength(); + sal_Int32 nLengthRight = rhs.getLength(); + + // first check the two lengths + if (nLengthLeft < nLengthRight) + return sal_True; + if (nLengthLeft > nLengthRight) + return sal_False; + + // both sequences have the same length -> check the type names + const ::com::sun::star::uno::Type* pTypesLeft = lhs.getConstArray(); + const ::com::sun::star::uno::Type* pTypesRight = rhs.getConstArray(); + for (sal_Int32 i=0; i<nLengthLeft; ++i, ++pTypesLeft, ++pTypesRight) + { + sal_Int32 nTypeNameCompare = pTypesLeft->getTypeName().compareTo(pTypesRight->getTypeName()); + if (nTypeNameCompare < 0) + return sal_True; + if (nTypeNameCompare > 0) + return sal_False; + } + + // both sequences are equal ... + return sal_False; + } +}; + +// declare the map +DECLARE_STL_MAP ( TypeSequence, + ::cppu::OImplementationId, + TypeSequenceLess, + MapType2Id + ); + +//......................................................................... +} // namespace utl +//......................................................................... + +//========================================================================= +/** defines a helper class for implementing the XTypeProvider::getImplementationId. + it maps sequences of ::com::sun::star::uno::Type to implementation ids + (which means sequences of bytes).<BR> + As there is no possibility to determine the time where the id's are no longer + needed (e.g. because the last instance of the class using this mechanism died) + the helper is "refcounted", i.e. there are acquire and release methods. + To simplify this there is a class classname##Ref which you may want to + use as an member of your classes. + <BR><BR> + As we don't want a global helper class which handles implementation id's + of components from all over the office (supposing somebody want's to use this :) + this is only a define. Wherever you have a "closed" area (which is small enough + and large enough :), see below) where diffenrent components want to use an id helper, + define your own one with this macro.<BR> + The more classes use this helper, the later redundant map entries will be + cleared. The less classes use it, the earlier map entries which may have + been reused will be cleared. +*/ +#define DECLARE_IMPLEMENTATIONID_HELPER(_namespace, classname) \ +namespace _namespace { \ +class classname \ +{ \ + friend class classname##Ref; \ + \ + static sal_Int32 s_nReferenced; \ + static void* s_pMap; \ + \ + static ::osl::Mutex s_aMutex; \ + \ +public: \ + static void acquire(); \ + static void release(); \ + \ + static ::com::sun::star::uno::Sequence< sal_Int8 > getImplementationId( \ + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _rTypes); \ + \ +private: \ + static void implCreateMap(); \ + \ + classname() { } \ +}; \ + \ +/*=======================================================================*/ \ +class classname##Ref \ +{ \ +public: \ + classname##Ref() { classname::acquire(); } \ + ~classname##Ref() { classname::release(); } \ +}; \ + \ +} /* _namespace */ \ + \ + +/************************************************************************* +************************************************************************** +*************************************************************************/ + +/** implement an id helper +*/ +#define IMPLEMENT_IMPLEMENTATIONID_HELPER(_namespace, classname) \ +namespace _namespace { \ + \ +/*=======================================================================*/ \ + \ +sal_Int32 classname::s_nReferenced(0); \ +void* classname::s_pMap = NULL; \ +::osl::Mutex classname::s_aMutex; \ + \ +/*-----------------------------------------------------------------------*/ \ +void classname::acquire() \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + ++s_nReferenced; \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +void classname::release() \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + if (!--s_nReferenced) \ + { \ + delete static_cast< ::utl::MapType2Id *>( s_pMap ); \ + s_pMap = NULL; \ + } \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId( \ + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _rTypes) \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + DBG_ASSERT(s_nReferenced, \ + "classname::getImplementationId : you need to hold a reference to this class in order to use it !"); \ + /* give the calling class a member of type classname##Ref and all is fine .... */ \ + \ + implCreateMap(); \ + \ + ::utl::MapType2Id* pMap = static_cast< ::utl::MapType2Id *>(s_pMap); \ + \ + ::cppu::OImplementationId& rId = (*pMap)[_rTypes]; \ + /* this will create an entry for the given type sequence, if neccessary */ \ + \ + return rId.getImplementationId(); \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +void classname::implCreateMap() \ +{ \ + if (s_pMap) \ + return; \ + s_pMap = new ::utl::MapType2Id(); \ +} \ + \ + \ +} /* _namespace */ \ + \ + + +#endif // _UNOTOOLS_ID_HELPER_HXX_ + diff --git a/unotools/inc/unotools/intlwrapper.hxx b/unotools/inc/unotools/intlwrapper.hxx new file mode 100644 index 000000000000..a48c9d20d0f4 --- /dev/null +++ b/unotools/inc/unotools/intlwrapper.hxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * 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: intlwrapper.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. + * + ************************************************************************/ +#include "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_INTLWRAPPER_HXX +#define _UNOTOOLS_INTLWRAPPER_HXX +#include <unotools/charclass.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/calendarwrapper.hxx> +#include <unotools/collatorwrapper.hxx> +#include <i18npool/lang.h> + + +/** + A wrapper of I18N wrappers. Using this is more expensive than using some + single wrapper classes so use it only if you must pass a single pointer + without knowing in advance what is needed, e.g. for + SfxPoolItem::GetPresentation(). Remember that this wrapper was only created + for convenience to bypass some oddities, if possible don't use it. <p> + + Implemented are only the const get...() methods of the wrappers, which are + loaded on demand, for consistency reasons no change of locale is possible. + Only default calendar and default collator are supported. <p> + + One exception though is the calendar wrapper: to be able to set a value and + retrieve calendar values it is not const, so methods using this should + reset the calendar to the previous value if it isn't sure where the + IntlWrapper did come from. <p> + */ +class UNOTOOLS_DLLPUBLIC IntlWrapper +{ +private: + + ::com::sun::star::lang::Locale aLocale; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + + CharClass* pCharClass; + LocaleDataWrapper* pLocaleData; + CalendarWrapper* pCalendar; + CollatorWrapper* pCollator; + CollatorWrapper* pCaseCollator; + + LanguageType eLanguage; + + void ImplNewCharClass() const; + void ImplNewLocaleData() const; + void ImplNewCalendar() const; + void ImplNewCollator( BOOL bCaseSensitive ) const; + + +public: + IntlWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::lang::Locale& rLocale + ); + IntlWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + LanguageType eLang + ); + ~IntlWrapper(); + + LanguageType getLanguage() const { return eLanguage; } + const ::com::sun::star::lang::Locale& getLocale() const { return aLocale; } + + const CharClass* getCharClass() const + { + if ( !pCharClass ) + ImplNewCharClass(); + return pCharClass; + } + const LocaleDataWrapper* getLocaleData() const + { + if ( !pLocaleData ) + ImplNewLocaleData(); + return pLocaleData; + } + CalendarWrapper* getCalendar() const + { + if ( !pCalendar ) + ImplNewCalendar(); + return pCalendar; + } + /// case insensitive collator, simple IGNORE_CASE + const CollatorWrapper* getCollator() const + { + if ( !pCollator ) + ImplNewCollator( FALSE ); + return pCollator; + } + /// case sensitive collator + const CollatorWrapper* getCaseCollator() const + { + if ( !pCaseCollator ) + ImplNewCollator( TRUE ); + return pCaseCollator; + } +}; + +#endif // _UNOTOOLS_INTLWRAPPER_HXX diff --git a/unotools/inc/unotools/localedatawrapper.hxx b/unotools/inc/unotools/localedatawrapper.hxx new file mode 100644 index 000000000000..5af352dd33c1 --- /dev/null +++ b/unotools/inc/unotools/localedatawrapper.hxx @@ -0,0 +1,366 @@ +/************************************************************************* + * + * 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: localedatawrapper.hxx,v $ + * $Revision: 1.31 $ + * + * 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 _UNOTOOLS_LOCALEDATAWRAPPER_HXX +#define _UNOTOOLS_LOCALEDATAWRAPPER_HXX + +#include <tools/string.hxx> +#include <com/sun/star/i18n/XLocaleData2.hpp> +#include <com/sun/star/i18n/LocaleItem.hpp> +#include <com/sun/star/i18n/reservedWords.hpp> +#include <unotools/readwritemutexguard.hxx> +#include "unotools/unotoolsdllapi.h" + +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED +#include <boost/shared_ptr.hpp> +#endif + + +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} +class Date; +class Time; +class CalendarWrapper; + + +enum DateFormat { + MDY, + DMY, + YMD +}; + + +enum MeasurementSystem { + MEASURE_METRIC, + MEASURE_US +}; + + +class UNOTOOLS_DLLPUBLIC LocaleDataWrapper +{ + static BYTE nLocaleDataChecking; // 0:=dontknow, 1:=yes, 2:=no + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XLocaleData2 > xLD; + ::com::sun::star::lang::Locale aLocale; + ::boost::shared_ptr< ::com::sun::star::i18n::Calendar > xDefaultCalendar; + ::com::sun::star::i18n::LocaleDataItem aLocaleDataItem; + ::com::sun::star::uno::Sequence< ::rtl::OUString > aReservedWordSeq; + ::com::sun::star::uno::Sequence< sal_Int32 > aGrouping; + // cached items + String aLocaleItem[::com::sun::star::i18n::LocaleItem::COUNT]; + String aReservedWord[::com::sun::star::i18n::reservedWords::COUNT]; + String aCurrSymbol; + String aCurrBankSymbol; + int nDateFormat; + int nLongDateFormat; + USHORT nCurrPositiveFormat; + USHORT nCurrNegativeFormat; + USHORT nCurrDigits; + BOOL bLocaleDataItemValid; + BOOL bReservedWordValid; + mutable ::utl::ReadWriteMutex aMutex; + + // dummies, to be implemented or provided by XML locale data + sal_Unicode cCurrZeroChar; + + + // not implemented, prevent usage + LocaleDataWrapper( const LocaleDataWrapper& ); + LocaleDataWrapper& operator=( const LocaleDataWrapper& ); + + // whenever Locale changes + void invalidateData(); + + void getOneLocaleItemImpl( sal_Int16 nItem ); + const String& getOneLocaleItem( sal_Int16 nItem ) const; + + void getOneReservedWordImpl( sal_Int16 nWord ); + const String& getOneReservedWord( sal_Int16 nWord ) const; + + void getCurrSymbolsImpl(); + void getCurrFormatsImpl(); + + void scanCurrFormatImpl( const String& rCode, + xub_StrLen nStart, xub_StrLen& nSign, + xub_StrLen& nPar, xub_StrLen& nNum, + xub_StrLen& nBlank, xub_StrLen& nSym ); + + void getDateFormatsImpl(); + DateFormat scanDateFormatImpl( const String& rCode ); + + void getDefaultCalendarImpl(); + + sal_Unicode* ImplAddFormatNum( sal_Unicode* pBuf, + sal_Int64 nNumber, USHORT nDecimals, + BOOL bUseThousandSep, BOOL bTrailingZeros ) const; + + void getDigitGroupingImpl(); + +public: + LocaleDataWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::lang::Locale& rLocale + ); + ~LocaleDataWrapper(); + + /** Get the service factory, meant to be able to create a CalendarWrapper + from a LocaleDataWrapper. Note that the service factory may be + non-existent if this LocaleDataWrapper was created without one and + lives "on the grassland". The CalendarWrapper ctor can handle that + though. */ + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & getServiceFactory() + const { return xSMgr; } + + /// set a new Locale to request + void setLocale( const ::com::sun::star::lang::Locale& rLocale ); + + /// get current requested Locale + const ::com::sun::star::lang::Locale& getLocale() const; + + /// get current loaded Locale, which might differ from the requested Locale + ::com::sun::star::lang::Locale getLoadedLocale() const; + + + // Wrapper implementations of service LocaleData + + ::com::sun::star::i18n::LanguageCountryInfo getLanguageCountryInfo() const; + ::com::sun::star::i18n::LocaleDataItem getLocaleItem() const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::Calendar > getAllCalendars() const; + /// NOTE: this wraps XLocaleData2::getAllCurrencies2() in fact. + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::Currency2 > getAllCurrencies() const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::FormatElement > getAllFormats() const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::Implementation > getCollatorImplementations() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > getTransliterations() const; + ::com::sun::star::i18n::ForbiddenCharacters getForbiddenCharacters() const; + ::com::sun::star::uno::Sequence< ::rtl::OUString > getReservedWord() const; + ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > getAllInstalledLocaleNames() const; + + /// same as the wrapper implementation but static + static ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > getInstalledLocaleNames(); + + /** Get LanguageTypes for all installed locales which are unambiguous + convertible back and forth between locale ISO strings and MS-LCID + LanguageType. Upon the first time the function is called when + locale data checking is enabled, messages are shown for locales not + matching, excluding already known problems. + (e.g. used in number formatter dialog init) + */ + static ::com::sun::star::uno::Sequence< sal_uInt16 > getInstalledLanguageTypes(); + + /// maps the LocaleData string to the International enum + MeasurementSystem mapMeasurementStringToEnum( const String& rMS ) const; + + /// Convenience method to obtain the default calendar. + const ::boost::shared_ptr< ::com::sun::star::i18n::Calendar > getDefaultCalendar() const; + + /// Convenience method to obtain the day names of the default calendar. + const ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getDefaultCalendarDays() const; + + /// Convenience method to obtain the month names of the default calendar. + const ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > getDefaultCalendarMonths() const; + + /** Obtain digit grouping. The usually known grouping by thousands (#,###) + is actually only one of possible groupings. Another one, for example, + used in India is group by 3 and then by 2 indefinitely (#,##,###). The + integer sequence returned here specifies grouping from right to left + (!), with a 0 entry designating the end of rules and the previous value + to be repeated indefinitely. Hence the sequence {3,0} specifies the + usual grouping by thousands, whereas the sequence {3,2,0} specifies + Indian grouping. The sal_Int32* getConstArray() can be passed directly + to the ::rtl::math::doubleToString() methods as argument for the + pGroups parameter. */ + const ::com::sun::star::uno::Sequence< sal_Int32 > getDigitGrouping() const; + + // Functionality of class International methods, LocaleItem + + inline const String& getDateSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DATE_SEPARATOR ); } + inline const String& getNumThousandSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::THOUSAND_SEPARATOR ); } + inline const String& getNumDecimalSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DECIMAL_SEPARATOR ); } + inline const String& getTimeSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_SEPARATOR ); } + inline const String& getTime100SecSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_100SEC_SEPARATOR ); } + inline const String& getListSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LIST_SEPARATOR ); } + inline const String& getQuotationMarkStart() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::SINGLE_QUOTATION_START ); } + inline const String& getQuotationMarkEnd() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::SINGLE_QUOTATION_END ); } + inline const String& getDoubleQuotationMarkStart() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DOUBLE_QUOTATION_START ); } + inline const String& getDoubleQuotationMarkEnd() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DOUBLE_QUOTATION_END ); } + inline const String& getMeasurementSystem() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::MEASUREMENT_SYSTEM ); } + inline MeasurementSystem getMeasurementSystemEnum() const + { return mapMeasurementStringToEnum( getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::MEASUREMENT_SYSTEM ) ); } + inline const String& getTimeAM() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_AM ); } + inline const String& getTimePM() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_PM ); } + inline const String& getLongDateDayOfWeekSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_DAY_OF_WEEK_SEPARATOR ); } + inline const String& getLongDateDaySep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_DAY_SEPARATOR ); } + inline const String& getLongDateMonthSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_MONTH_SEPARATOR ); } + inline const String& getLongDateYearSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_YEAR_SEPARATOR ); } + + // currency + const String& getCurrSymbol() const; + const String& getCurrBankSymbol() const; + USHORT getCurrPositiveFormat() const; + USHORT getCurrNegativeFormat() const; + USHORT getCurrDigits() const; + + // simple date and time formatting + DateFormat getDateFormat() const; + DateFormat getLongDateFormat() const; + /// only numerical values of Gregorian calendar + String getDate( const Date& rDate ) const; + String getTime( const Time& rTime, BOOL bSec = TRUE, + BOOL b100Sec = FALSE ) const; + String getDuration( const Time& rTime, + BOOL bSec = TRUE, BOOL b100Sec = FALSE ) const; + + /** The CalendarWrapper already <b>MUST</b> + have loaded a calendar. + @param nDisplayDayOfWeek + 0 := abbreviated name + 1 := full name + @param bDayOfMonthWithLeadingZero + <FALSE/> := without leading zero + <TRUE/> := with leading zero if <10 + @param nDisplayMonth + 0 := abbreviated name + 1 := full name + @param bTwoDigitYear + <FALSE/> := full year + <TRUE/> := year % 100 + */ + String getLongDate( const Date& rDate, + CalendarWrapper& rCal, + sal_Int16 nDisplayDayOfWeek = 1, + sal_Bool bDayOfMonthWithLeadingZero = sal_False, + sal_Int16 nDisplayMonth = 1, + sal_Bool bTwoDigitYear = sal_False + ) const; + + /** Simple number formatting + @param nNumber + value * 10**nDecimals + @param bTrailingZeros + </TRUE> := always display trailing zeros in + decimal places, even if integer value. + </FALSE> := trailing zeros are only displayed + if the value is not an integer value. + */ + String getNum( sal_Int64 nNumber, USHORT nDecimals, + BOOL bUseThousandSep = TRUE, + BOOL bTrailingZeros = TRUE ) const; + + /// "Secure" currency formatted string. + String getCurr( sal_Int64 nNumber, USHORT nDecimals, + const String& rCurrencySymbol, + BOOL bUseThousandSep = TRUE ) const; + /** Default currency formatted string, use with + care as default currency may change in any + locale, for example, DEM -> EUR */ + String getCurr( sal_Int64 nNumber, USHORT nDecimals, + BOOL bUseThousandSep = TRUE ) const + { return getCurr( nNumber, nDecimals, + getCurrSymbol(), bUseThousandSep ); } + + // dummy returns, to be implemented + inline sal_Unicode getCurrZeroChar() const + { return cCurrZeroChar; } + inline BOOL isNumLeadingZero() const + { return TRUE; } + /// standard decimal places + inline USHORT getNumDigits() const + { return 2; } + inline BOOL isNumTrailingZeros() const + { return TRUE; } + + + // reserved words + + inline const String& getTrueWord() const + { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::TRUE_WORD ); } + inline const String& getFalseWord() const + { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::FALSE_WORD ); } + /// return a quarter string matching nQuarter (0..3) => "1st quarter" .. "4th quarter" + inline const String& getQuarterWord( sal_Int16 nQuarter ) const + { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::QUARTER1_WORD + nQuarter ); } + inline const String& getAboveWord() const + { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::ABOVE_WORD ); } + inline const String& getBelowWord() const + { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::BELOW_WORD ); } + /// return a quarter abbreviation string matching nQuarter (0..3) => "Q1" .. "Q2" + inline const String& getQuarterAbbreviation( sal_Int16 nQuarter ) const + { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::QUARTER1_ABBREVIATION + nQuarter ); } + + /** Return whether locale data checks are enabled. + Checks are enabled if the environment variable + OOO_ENABLE_LOCALE_DATA_CHECKS is set to 'Y' or 'Yes' (or any other + string starting with 'Y') or '1'. + Also used in conjunction with the number formatter. */ + static inline bool areChecksEnabled() + { + if (nLocaleDataChecking == 0) + evaluateLocaleDataChecking(); + return nLocaleDataChecking == 1; + } + + /** Append locale info to string, used with locale data checking. + A string similar to "de_DE requested\n en_US loaded" is appended. */ + String& appendLocaleInfo( String& rDebugMsg ) const; + + /** Ouput a message during locale data checking. The (UTF-8) string is + written to stderr and in a non-product build or if DBG_UTIL is enabled + also raised as an assertion message box. */ + static void outputCheckMessage( const String& rMsg ); + static void outputCheckMessage( const char* pStr); + +private: + static void evaluateLocaleDataChecking(); +}; + + +#endif // _UNOTOOLS_LOCALEDATAWRAPPER_HXX diff --git a/unotools/inc/unotools/localfilehelper.hxx b/unotools/inc/unotools/localfilehelper.hxx new file mode 100644 index 000000000000..a5b6fb44d818 --- /dev/null +++ b/unotools/inc/unotools/localfilehelper.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * 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: localfilehelper.hxx,v $ + * $Revision: 1.9 $ + * + * 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 _UNOTOOLS_LOCALFILEHELPER_HXX +#define _UNOTOOLS_LOCALFILEHELPER_HXX + +#include <com/sun/star/uno/Sequence.hxx> +#include "unotools/unotoolsdllapi.h" + +#include <rtl/ustring.hxx> +#include <tools/string.hxx> + +namespace utl +{ + +class UNOTOOLS_DLLPUBLIC LocalFileHelper +{ +public: + /** + Converts a "physical" file name into a "UCB compatible" URL ( if possible ). + If no UCP is available for the local file system, sal_False and an empty URL is returned. + Returning sal_True and an empty URL means that the URL doesn't point to a local file. + */ + static sal_Bool ConvertPhysicalNameToURL( const String& rName, String& rReturn ); + static sal_Bool ConvertSystemPathToURL( const String& rName, const String& rBaseURL, String& rReturn ); + + /** + Converts a "UCB compatible" URL into a "physical" file name. + If no UCP is available for the local file system, sal_False and an empty file name is returned, + otherwise sal_True and a valid URL, because a file name can always be converted if a UCP for the local + file system is present ( watch: this doesn't mean that this file really exists! ) + */ + static sal_Bool ConvertURLToPhysicalName( const String& rName, String& rReturn ); + static sal_Bool ConvertURLToSystemPath( const String& rName, String& rReturn ); + + static sal_Bool IsLocalFile( const String& rName ); + static sal_Bool IsFileContent( const String& rName ); + + static ::com::sun::star::uno::Sequence< ::rtl::OUString > + GetFolderContents( const ::rtl::OUString& rFolder, sal_Bool bFolder ); +}; + +} + +#endif diff --git a/unotools/inc/unotools/nativenumberwrapper.hxx b/unotools/inc/unotools/nativenumberwrapper.hxx new file mode 100644 index 000000000000..35f7ba632ca0 --- /dev/null +++ b/unotools/inc/unotools/nativenumberwrapper.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * 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: nativenumberwrapper.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. + * + ************************************************************************/ +#include "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_NATIVENUMBERWRAPPER_HXX +#define _UNOTOOLS_NATIVENUMBERWRAPPER_HXX +#include <com/sun/star/i18n/XNativeNumberSupplier.hpp> + +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + + +class UNOTOOLS_DLLPUBLIC NativeNumberWrapper +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XNativeNumberSupplier > xNNS; + // not implemented, prevent usage + NativeNumberWrapper( const NativeNumberWrapper& ); + NativeNumberWrapper& operator=( const NativeNumberWrapper& ); + +public: + NativeNumberWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF + ); + + ~NativeNumberWrapper(); + + // Wrapper implementations of XNativeNumberSupplier + + ::rtl::OUString getNativeNumberString( + const ::rtl::OUString& rNumberString, + const ::com::sun::star::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode ) const; + + sal_Bool isValidNatNum( + const ::com::sun::star::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode ) const; + + ::com::sun::star::i18n::NativeNumberXmlAttributes convertToXmlAttributes( + const ::com::sun::star::lang::Locale& rLocale, + sal_Int16 nNativeNumberMode ) const; + + sal_Int16 convertFromXmlAttributes( + const ::com::sun::star::i18n::NativeNumberXmlAttributes& rAttr ) const; + +}; + +#endif // _UNOTOOLS_NATIVENUMBERWRAPPER_HXX diff --git a/unotools/inc/unotools/numberformatcodewrapper.hxx b/unotools/inc/unotools/numberformatcodewrapper.hxx new file mode 100644 index 000000000000..8e4f1ce793d0 --- /dev/null +++ b/unotools/inc/unotools/numberformatcodewrapper.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * 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: numberformatcodewrapper.hxx,v $ + * $Revision: 1.7 $ + * + * 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 _UNOTOOLS_NUMBERFORMATCODEWRAPPER_HXX +#define _UNOTOOLS_NUMBERFORMATCODEWRAPPER_HXX + +#include <com/sun/star/i18n/XNumberFormatCode.hpp> +#include "unotools/unotoolsdllapi.h" + +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + + +class UNOTOOLS_DLLPUBLIC NumberFormatCodeWrapper +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XNumberFormatCode > xNFC; + ::com::sun::star::lang::Locale aLocale; + + // not implemented, prevent usage + NumberFormatCodeWrapper( const NumberFormatCodeWrapper& ); + NumberFormatCodeWrapper& operator=( const NumberFormatCodeWrapper& ); + +public: + NumberFormatCodeWrapper( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::lang::Locale& rLocale + ); + + ~NumberFormatCodeWrapper(); + + + /// set a new Locale + void setLocale( const ::com::sun::star::lang::Locale& rLocale ); + + /// get current Locale + const ::com::sun::star::lang::Locale& getLocale() const { return aLocale; } + + + // Wrapper implementations of class NumberFormatCodeMapper + + ::com::sun::star::i18n::NumberFormatCode getDefault( sal_Int16 nFormatType, sal_Int16 nFormatUsage ) const; + ::com::sun::star::i18n::NumberFormatCode getFormatCode( sal_Int16 nFormatIndex ) const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode > getAllFormatCode( sal_Int16 nFormatUsage ) const; + ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode > getAllFormatCodes() const; + +}; + +#endif // _UNOTOOLS_NUMBERFORMATCODEWRAPPER_HXX diff --git a/unotools/inc/unotools/processfactory.hxx b/unotools/inc/unotools/processfactory.hxx new file mode 100644 index 000000000000..795f4ee8839f --- /dev/null +++ b/unotools/inc/unotools/processfactory.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * 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: processfactory.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 _UNOTOOLS_PROCESSFACTORY_HXX_ +#define _UNOTOOLS_PROCESSFACTORY_HXX_ + +#include "unotools/unotoolsdllapi.h" +#include <comphelper/processfactory.hxx> +#include <com/sun/star/uno/Reference.hxx> + +namespace com { namespace sun { namespace star { namespace lang { + class XMultiServiceFactory; +} } } } + +namespace utl +{ + +/** + * This function set the process service factory. + * + * @author Juergen Schmidt + */ +UNOTOOLS_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 + */ +UNOTOOLS_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getProcessServiceFactory(); + +} + +#endif // _UNOTOOLS_PROCESSFACTORY_HXX_ + diff --git a/unotools/inc/unotools/progresshandlerwrap.hxx b/unotools/inc/unotools/progresshandlerwrap.hxx new file mode 100644 index 000000000000..c8394dc8577c --- /dev/null +++ b/unotools/inc/unotools/progresshandlerwrap.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * 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: progresshandlerwrap.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. + * + ************************************************************************/ +#include "unotools/unotoolsdllapi.h" + +#ifndef _UTL_PROGRESSHANDLERWRAP_HXX_ +#define _UTL_PROGRESSHANDLERWRAP_HXX_ +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/ucb/XProgressHandler.hpp> + +namespace utl +{ + +class UNOTOOLS_DLLPUBLIC ProgressHandlerWrap : public ::cppu::WeakImplHelper1< ::com::sun::star::ucb::XProgressHandler > +{ + ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > m_xStatusIndicator; + +public: + ProgressHandlerWrap( ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > xSI ); + + // XProgressHandler + virtual void SAL_CALL push( const ::com::sun::star::uno::Any& Status ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL update( const ::com::sun::star::uno::Any& Status ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL pop() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace utl + +#endif // _UTL_PROGRESSHANDLERWRAP_HXX_ + diff --git a/unotools/inc/unotools/propertysethelper.hxx b/unotools/inc/unotools/propertysethelper.hxx new file mode 100644 index 000000000000..04b027dc3546 --- /dev/null +++ b/unotools/inc/unotools/propertysethelper.hxx @@ -0,0 +1,99 @@ +/************************************************************************* + * + * 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: propertysethelper.hxx,v $ + * $Revision: 1.3 $ + * + * 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 _UTL_PROPERTYSETHELPER_HXX_ +#define _UTL_PROPERTYSETHELPER_HXX_ + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> + +//========================================================================= +//= property helper classes +//========================================================================= + +//... namespace utl ....................................................... +namespace utl +{ +//......................................................................... + +class PropertySetInfo; +struct PropertyMapEntry; +class PropertySetHelperImpl; + +class 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 utl::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 utl::PropertyMapEntry** ppEntries, ::com::sun::star::uno::Any* pValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ) = 0; + + virtual void _getPropertyStates( const utl::PropertyMapEntry** ppEntries, ::com::sun::star::beans::PropertyState* pStates ) throw(::com::sun::star::beans::UnknownPropertyException ); + virtual void _setPropertyToDefault( const utl::PropertyMapEntry* pEntry ) throw(::com::sun::star::beans::UnknownPropertyException ); + virtual ::com::sun::star::uno::Any _getPropertyDefault( const utl::PropertyMapEntry* pEntry ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException ); + +public: + PropertySetHelper( utl::PropertySetInfo* pInfo ) 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 utl ....................................................... + +#endif // _UTL_PROPERTYSETHELPER_HXX_ + diff --git a/unotools/inc/unotools/propertysetinfo.hxx b/unotools/inc/unotools/propertysetinfo.hxx new file mode 100644 index 000000000000..cd44940eb781 --- /dev/null +++ b/unotools/inc/unotools/propertysetinfo.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * 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: propertysetinfo.hxx,v $ + * $Revision: 1.3 $ + * + * 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 _UTL_PROPERTSETINFO_HXX_ +#define _UTL_PROPERTSETINFO_HXX_ + +#include <com/sun/star/uno/Type.h> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/stl_types.hxx> + +//========================================================================= +//= property helper classes +//========================================================================= + +//... namespace utl ....................................................... +namespace utl +{ +//......................................................................... + +struct PropertyMapEntry +{ + const sal_Char* mpName; + sal_uInt16 mnNameLen; + sal_uInt16 mnWhich; + const com::sun::star::uno::Type* mpType; + sal_Int16 mnFlags; + 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 PropertySetInfo : public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo > +{ +private: + PropertyMapImpl* mpMap; +public: + PropertySetInfo() 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 + */ + void add( PropertyMapEntry* pMap ) 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 utl ....................................................... + +#endif // _UTL_PROPERTSETINFO_HXX_ + diff --git a/unotools/inc/unotools/querydeep.hxx b/unotools/inc/unotools/querydeep.hxx new file mode 100644 index 000000000000..50af53d35dce --- /dev/null +++ b/unotools/inc/unotools/querydeep.hxx @@ -0,0 +1,489 @@ +/************************************************************************* + * + * 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: querydeep.hxx,v $ + * $Revision: 1.3 $ + * + * 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 _UNOTOOLS_QUERYDEEPINTERFACE_HXX +#define _UNOTOOLS_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 utl +{ + +//-------------------------------------------------------------------------------------------------------- +/** + * 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, + ::getCppuType(static_cast<const ::com::sun::star::uno::Reference<Interface> *>(0))); +} + +//-------------------------------------------------------------------------------------------------------- +// 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface10 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface10 > *>(0)))) + return ::com::sun::star::uno::Any( &p10, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface11 > *>(0)))) + 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, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface10 > *>(0)))) + return ::com::sun::star::uno::Any( &p10, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface11 > *>(0)))) + return ::com::sun::star::uno::Any( &p11, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface12 > *>(0)))) + return ::com::sun::star::uno::Any( &p12, rType ); + else + return ::com::sun::star::uno::Any(); +} + +} // namespace utl + +#endif // _UNOTOOLS_QUERYDEEPINTERFACE_HXX + diff --git a/unotools/inc/unotools/readwritemutexguard.hxx b/unotools/inc/unotools/readwritemutexguard.hxx new file mode 100644 index 000000000000..46e3d36f2eac --- /dev/null +++ b/unotools/inc/unotools/readwritemutexguard.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * 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: readwritemutexguard.hxx,v $ + * $Revision: 1.3 $ + * + * 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_UNOTOOLS_READWRITEMUTEXGUARD_HXX +#define INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_HXX + +#include <osl/mutex.hxx> + +namespace utl { + +class ReadWriteGuard; +class ReadWriteMutex +{ + friend class ReadWriteGuard; + + sal_uInt32 nReadCount; + sal_uInt32 nBlockCriticalCount; + ::osl::Mutex* pMutex; + ::osl::Mutex* pWriteMutex; + +public: + ReadWriteMutex() + : nReadCount(0) + , nBlockCriticalCount(0) + , pMutex( new ::osl::Mutex ) + , pWriteMutex( new ::osl::Mutex ) + {} + ~ReadWriteMutex() + { + delete pMutex; + delete pWriteMutex; + } +}; + + +namespace ReadWriteGuardMode { +const sal_Int32 nWrite = 0x01; +const sal_Int32 nCriticalChange = 0x02 | nWrite; +const sal_Int32 nBlockCritical = 0x04; // only a block, not a read, exclusive flag! +} + +/** Enable multiple threads to read simultaneously, but a write blocks all + other reads and writes, and a read blocks any write. + Used in I18N wrappers to be able to maintain a single instance of a wrapper + for the standard Office locale. + NEVER construct a writing guard if there is already a reading guard in the + same context, the following will dead lock EVEN IN THE SAME THREAD! + void foo() + { + ReadWriteGuard aGuard1( aMutex ); + bar(); + } + void bar() + { + // waits forever for aGuard1 + ReadWriteGuard aGuard2( aMutex, ReadWriteGuardMode::nWrite ); + } + */ +class ReadWriteGuard +{ + ReadWriteMutex& rMutex; + sal_Int32 nMode; +public: + ReadWriteGuard( + ReadWriteMutex& rMutex, + sal_Int32 nRequestMode = 0 // read only + ); + ~ReadWriteGuard(); + + /** Be careful with this, it does wait for ANY read to complete. + The following will dead lock EVEN IN THE SAME THREAD! + void foo() + { + ReadWriteGuard aGuard1( aMutex ); + bar(); + } + void bar() + { + ReadWriteGuard aGuard2( aMutex ); + aGuard2.changeReadToWrite(); // waits forever for aGuard1 + } + */ + void changeReadToWrite(); +}; + +} // namespace utl + +#endif // INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_HXX + diff --git a/unotools/inc/unotools/regpathhelper.hxx b/unotools/inc/unotools/regpathhelper.hxx new file mode 100644 index 000000000000..4dd2b5fbeb79 --- /dev/null +++ b/unotools/inc/unotools/regpathhelper.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * 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: regpathhelper.hxx,v $ + * $Revision: 1.3 $ + * + * 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 _UNOTOOLS_REGPATHHELPER_HXX_ +#define _UNOTOOLS_REGPATHHELPER_HXX_ + +#include <rtl/ustring.hxx> + +namespace utl +{ + +/** + * 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/unotools/inc/unotools/sharedunocomponent.hxx b/unotools/inc/unotools/sharedunocomponent.hxx new file mode 100644 index 000000000000..10c552c38336 --- /dev/null +++ b/unotools/inc/unotools/sharedunocomponent.hxx @@ -0,0 +1,373 @@ +/************************************************************************* + * + * 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: sharedunocomponent.hxx,v $ + * $Revision: 1.7 $ + * + * 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 UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX +#define UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX + +#include "unotoolsdllapi.h" + +#include <boost/shared_ptr.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <rtl/ref.hxx> + +namespace com { namespace sun { namespace star { + namespace lang { + class XComponent; + } +} } } +//............................................................................ +namespace utl +{ +//............................................................................ + + //======================================================================== + //= DisposableComponent + //======================================================================== + /** is a class which controls lifetime of an UNO component via ->XComponent::dispose + + You'll usually never use this class directly, but only as parameter for a + ->SharedUNOComponent class. + */ + class UNOTOOLS_DLLPUBLIC DisposableComponent + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + m_xComponent; + + public: + /** constructs a ->DisposableComponent instance + + @param _rxComponent + the component whose life time should be controlled by the instance. Must not be <NULL/>. + */ + DisposableComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent ); + + /** disposes the component represented by the instance + + The component is queried for ->XComponent(which <em>must</em> be supported), + and ->XComponent::dispose is invoked. A failure of this invocation (e.g. a thrown + exception) is silenced in release builds, and reported in debug builds. + */ + ~DisposableComponent(); + + private: + DisposableComponent(); // never implemented + DisposableComponent( const DisposableComponent& ); // never implemented + DisposableComponent& operator=( const DisposableComponent& ); // never implemented + }; + + //======================================================================== + //= CloseableComponent + //======================================================================== + class CloseableComponentImpl; + /** is a class which controls lifetime of an UNO component via ->XCloseable::close + + You'll usually never use this class directly, but only as parameter for a + ->SharedUNOComponent class. + */ + class UNOTOOLS_DLLPUBLIC CloseableComponent + { + private: + /** Our IMPL class. + */ + ::rtl::Reference< CloseableComponentImpl > m_pImpl; + + public: + /** constructs a ->CloseableComponent instance + + @param _rxComponent + the component whose life time should be controlled by the instance. Must not be <NULL/>. + */ + CloseableComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent ); + + /** destroys resources associated with this instance, and disposes the component + + The component is queried for ->XCloseable (which <em>must</em> be supported), + and ->XCloseable::close is invoked, with delivering the ownership. + If the invocation fails with a ->CloseVetoException, this is ignored, since in + this case the vetoing instance took the ownership. + + Any other failure will be reported in a debug version via assertion mechanisms, + and silenced in release builds. + */ + ~CloseableComponent(); + + private: + CloseableComponent(); // never implemented + CloseableComponent( const CloseableComponent& ); // never implemented + CloseableComponent& operator=( const CloseableComponent& ); // never implemented + }; + + //======================================================================== + //= SharedUNOComponent + //======================================================================== + /** is a helper class for sharing ownership of a UNO component + + If you need to share an UNO component, which normally needs a dedicated owner, + and is lifetime controlled by an explicit disposal action (not necessarily ->XComponent::dispose, + but <em>any</em> explicit method call, after which the object is considered + to be disposed), between different classes, ->SharedUNOComponent is what you need. + + Instead of passing around a <code>Reference< XFoo ></code>, and bothering + with ownership and disposal, you just use a <code>SharedUNOComponent< XFoo ></code>. + This instance can be passed around, including copying, and in nearly all respects behaves + like the original <code>Reference< XFoo ></code>. However, when the last + ->SharedUNOComponent referencing a certain <code>Reference< XFoo ></code> dies, it + will automatically get rid of the object held by this reference. + + @param INTERFACE + the UNO interface type as which the component should be held + + @param COMPONENT_HOLDER + a class which can be used to represent and dispose a UNO component. + The class must support (maybe explicit only) construction from a + <code>Reference< INTERFACE ></code>, and destruction. Upon destruction, + the class must dispose (by any suitable means) the component instance it was + constructed with. + */ + template < class INTERFACE, class COMPONENT = DisposableComponent > + class SharedUNOComponent + { + private: + typedef COMPONENT Component; + typedef ::boost::shared_ptr< Component > ComponentPointer; + + private: + ComponentPointer m_pComponent; + ::com::sun::star::uno::Reference< INTERFACE > m_xTypedComponent; + + public: + enum AssignmentMode + { + TakeOwnership, + NoTakeOwnership + }; + + public: + inline SharedUNOComponent() + { + } + + explicit inline SharedUNOComponent( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode eMode = TakeOwnership ) + { + reset( _rxComponent, eMode ); + } + +#ifndef EXCEPTIONS_OFF + inline SharedUNOComponent( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ) + { + set( _pInterface, _queryThrow ); + } + + inline SharedUNOComponent( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ) + { + set( _rRef, _queryThrow ); + } + + inline SharedUNOComponent( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ) + { + set( _rAny, _queryThrow ); + } + + inline SharedUNOComponent( const SharedUNOComponent& _rxComponent, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ) + { + set( _rxComponent, _setThrow ); + } +#endif + +// SharedUNOComponent& operator=( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent ); + // this operator is not implemented by intention. There is no canonic ownership after this operatoer + // would hvae been applied: Should the SharedUNOComponent have the ownership of the component, + // or shouldn't it? Hard to guess, and probably wrong in 50 percent of all cases, anyway. So, + // instead of tempting clients of this class to use such a dangerous operator, we do + // not offer it at all. If you need to assign a Reference< INTERFACE > to your SharedUNOComponent, + // use the ->reset method. + + /** assigns a new component, and releases the old one + */ + void reset( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode = TakeOwnership ); + + inline bool set( ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_Query _query ); + inline bool set( const ::com::sun::star::uno::BaseReference& _rRef, ::com::sun::star::uno::UnoReference_Query _query ); + inline bool set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_Query _query ); + +#ifndef EXCEPTIONS_OFF + inline void set( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ); + inline void set( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ); + inline void set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ); + + inline void set( const INTERFACE* _pInterface, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ); + inline void set( const ::com::sun::star::uno::Reference< INTERFACE >& _rRef, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ); + inline void set( const SharedUNOComponent& _rComp, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ); +#endif + + INTERFACE* SAL_CALL operator->() const; + + inline operator const ::com::sun::star::uno::Reference< INTERFACE >&() const + { + return m_xTypedComponent; + } + + inline const ::com::sun::star::uno::Reference< INTERFACE >& getTyped() const + { + return m_xTypedComponent; + } + + inline bool is() const + { + return m_xTypedComponent.is(); + } + + inline void clear() + { + m_pComponent.reset(); + m_xTypedComponent.clear(); + } + }; + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + INTERFACE* SAL_CALL SharedUNOComponent< INTERFACE, COMPONENT >::operator->() const + { + return m_xTypedComponent.operator->(); + } + + //------------------------------------------------------------------------- + // assignments + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::reset( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode ) + { + m_pComponent.reset( _eMode == TakeOwnership ? new COMPONENT( _rxComponent ) : NULL ); + m_xTypedComponent = _rxComponent; + } + + //------------------------------------------------------------------------- + // comparison operators + template < class INTERFACE, class COMPONENT > + bool operator==( const ::com::sun::star::uno::Reference< INTERFACE >& _rLHS, const SharedUNOComponent< INTERFACE, COMPONENT >& _rRHS ) + { + return _rLHS == _rRHS.getTyped(); + } + + template < class INTERFACE, class COMPONENT > + bool operator==( const SharedUNOComponent< INTERFACE, COMPONENT >& _rLHS, const ::com::sun::star::uno::Reference< INTERFACE >& _rRHS ) + { + return _rLHS.getTyped() == _rRHS; + } + + //------------------------------------------------------------------------- + // conversion to Any + template < class INTERFACE, class COMPONENT > + inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const SharedUNOComponent< INTERFACE, COMPONENT >& value ) SAL_THROW( () ) + { + rAny <<= value.getTyped(); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + inline ::com::sun::star::uno::Any SAL_CALL makeAny( const SharedUNOComponent< INTERFACE, COMPONENT >& value ) SAL_THROW( () ) + { + return makeAny( value.getTyped() ); + } + +#ifndef EXCEPTIONS_OFF + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _queryThrow ), TakeOwnership ); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _queryThrow ), TakeOwnership ); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _rAny, _queryThrow ), TakeOwnership ); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const INTERFACE* _pInterface, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _setThrow ), TakeOwnership ); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Reference< INTERFACE >& _rRef, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _setThrow ), TakeOwnership ); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + void SharedUNOComponent< INTERFACE, COMPONENT >::set( const SharedUNOComponent& _rComp, ::com::sun::star::uno::UnoReference_SetThrow _setThrow ) + { + *this = _rComp; + // provoke an exception in case the component is NULL + m_xTypedComponent.set( m_xTypedComponent, _setThrow ); + } +#endif + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + bool SharedUNOComponent< INTERFACE, COMPONENT >::set( ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_Query _query ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _query ) ); + return is(); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::BaseReference& _rRef, ::com::sun::star::uno::UnoReference_Query _query ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _query ) ); + return is(); + } + + //------------------------------------------------------------------------- + template < class INTERFACE, class COMPONENT > + bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_Query _query ) + { + reset( ::com::sun::star::uno::Reference< INTERFACE >( _rAny, _query ) ); + return is(); + } + +//............................................................................ +} // namespace utl +//............................................................................ + +#endif // UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX diff --git a/unotools/inc/unotools/streamhelper.hxx b/unotools/inc/unotools/streamhelper.hxx new file mode 100644 index 000000000000..0dd6534eaeaa --- /dev/null +++ b/unotools/inc/unotools/streamhelper.hxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * 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: streamhelper.hxx,v $ + * $Revision: 1.6 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_STREAMHELPER_HXX_ +#define _UNOTOOLS_STREAMHELPER_HXX_ +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <osl/mutex.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <tools/stream.hxx> + +namespace utl +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +/** + * The helper implementation for a using input streams based on SvLockBytes. + * + * @author Dirk Grobler + * @since 00/28/03 + */ + typedef ::cppu::WeakImplHelper2<stario::XInputStream, stario::XSeekable> InputStreamHelper_Base; + // needed for some compilers +class UNOTOOLS_DLLPUBLIC OInputStreamHelper : public InputStreamHelper_Base +{ + ::osl::Mutex m_aMutex; + SvLockBytesRef m_xLockBytes; + sal_uInt32 m_nActPos; + sal_Int32 m_nAvailable; // this is typically the chunk(buffer) size + +public: + OInputStreamHelper(const SvLockBytesRef& _xLockBytes, + sal_uInt32 _nAvailable, + sal_uInt32 _nPos = 0) + :m_xLockBytes(_xLockBytes) + ,m_nActPos(_nPos) + ,m_nAvailable(_nAvailable){} + +// staruno::XInterface + virtual void SAL_CALL acquire() throw (); + virtual void SAL_CALL release() throw (); + +// stario::XInputStream + virtual sal_Int32 SAL_CALL readBytes( staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes( staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL available( ) throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL closeInput( ) throw (stario::NotConnectedException, stario::IOException, staruno::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); +}; + +/** + * The helper implementation for a using output streams based on SvLockBytes. + * + * @author Dirk Grobler + * @since 00/28/03 + */ +typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamHelper_Base; + // needed for some compilers +class UNOTOOLS_DLLPUBLIC OOutputStreamHelper : public OutputStreamHelper_Base +{ + ::osl::Mutex m_aMutex; + SvLockBytesRef m_xLockBytes; + sal_uInt32 m_nActPos; + +public: + OOutputStreamHelper(const SvLockBytesRef& _xLockBytes, sal_uInt32 _nPos = 0) + :m_xLockBytes(_xLockBytes) + ,m_nActPos(_nPos){} + +// staruno::XInterface + virtual void SAL_CALL acquire() throw (); + virtual void SAL_CALL release() throw (); + +// stario::XOutputStream + virtual void SAL_CALL writeBytes( const staruno::Sequence< sal_Int8 >& aData ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL flush( ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL closeOutput( ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); +}; + +} // namespace utl + + +#endif // _UNOTOOLS_STREAM_WRAPPER_HXX_ + diff --git a/unotools/inc/unotools/streamsection.hxx b/unotools/inc/unotools/streamsection.hxx new file mode 100644 index 000000000000..4fa2e19b6e07 --- /dev/null +++ b/unotools/inc/unotools/streamsection.hxx @@ -0,0 +1,88 @@ +/************************************************************************* + * + * 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: streamsection.hxx,v $ + * $Revision: 1.3 $ + * + * 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 _UNOTOOLS_STREAMSECTION_HXX_ +#define _UNOTOOLS_STREAMSECTION_HXX_ + +#include <com/sun/star/io/XMarkableStream.hpp> +#include <com/sun/star/io/XDataInputStream.hpp> +#include <com/sun/star/io/XDataOutputStream.hpp> + +namespace utl +{ + + 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 OStreamSection +{ + staruno::Reference< stario::XMarkableStream > m_xMarkStream; + staruno::Reference< stario::XDataInputStream > m_xInStream; + staruno::Reference< stario::XDataOutputStream > m_xOutStream; + + sal_Int32 m_nBlockStart; + sal_Int32 m_nBlockLen; + +public: + /** starts reading of a "skippable" section of data within the given input stream<BR> + @param _rxInput the stream to read from. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + */ + OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput); + + /** starts writing of a "skippable" section of data into the given output stream + @param _rxOutput the stream the stream to write to. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + @param _nPresumedLength estimation for the length of the upcoming section. If greater 0, this + value will be written as section length and corrected (in the dtor) only if + needed. If you know how much bytes you are about to write, you may + want to use this param, saving some stream operations this way. + */ + OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0); + + /** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR> + If constructed for reading, any remaining bytes 'til the end of the section will be skipped. + */ + ~OStreamSection(); +}; + +} // namespace utl + +#endif // _UNOTOOLS_STREAMSECTION_HXX_ + + diff --git a/unotools/inc/unotools/streamwrap.hxx b/unotools/inc/unotools/streamwrap.hxx new file mode 100644 index 000000000000..714129540412 --- /dev/null +++ b/unotools/inc/unotools/streamwrap.hxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * 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: streamwrap.hxx,v $ + * $Revision: 1.10 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UTL_STREAM_WRAPPER_HXX_ +#define _UTL_STREAM_WRAPPER_HXX_ +#include <osl/mutex.hxx> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/implbase1.hxx> +#include <comphelper/uno3.hxx> + +class SvStream; + +namespace utl +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +//================================================================== +//= OInputStreamWrapper +//================================================================== +typedef ::cppu::WeakImplHelper1 < stario::XInputStream + > InputStreamWrapper_Base; + // needed for some compilers +/// helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XInputStream</type> +class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public InputStreamWrapper_Base +{ +protected: + ::osl::Mutex m_aMutex; + SvStream* m_pSvStream; + sal_Bool m_bSvStreamOwner : 1; + OInputStreamWrapper() + { m_pSvStream = 0; m_bSvStreamOwner = sal_False; } + void SetStream(SvStream* _pStream, sal_Bool bOwner ) + { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; } + +public: + OInputStreamWrapper(SvStream& _rStream); + OInputStreamWrapper(SvStream* pStream, sal_Bool bOwner=sal_False); + virtual ~OInputStreamWrapper(); + +// UNO Anbindung + DECLARE_UNO3_AGG_DEFAULTS(OInputStreamWrapper, InputStreamWrapper_Base); + +// 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); + +protected: + /// throws a NotConnectedException if the object is not connected anymore + void checkConnected() const; + /// throws an exception according to the error flag of m_pSvStream + void checkError() const; +}; + +//================================================================== +//= OSeekableInputStreamWrapper +//================================================================== +typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable + > OSeekableInputStreamWrapper_Base; +/** helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XInputStream</type> + which is seekable (i.e. supports the <type scope="com.sun.star.io">XSeekable</type> interface). +*/ +class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper : public ::cppu::ImplInheritanceHelper1 < OInputStreamWrapper, com::sun::star::io::XSeekable > +{ +protected: + OSeekableInputStreamWrapper() {} +public: + OSeekableInputStreamWrapper(SvStream& _rStream); + OSeekableInputStreamWrapper(SvStream* _pStream, sal_Bool _bOwner = sal_False); + + // XSeekable + virtual void SAL_CALL seek( sal_Int64 _nLocation ) 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); +}; + +//================================================================== +//= OOutputStreamWrapper +//================================================================== +typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base; + // needed for some compilers +class UNOTOOLS_DLLPUBLIC OOutputStreamWrapper : public OutputStreamWrapper_Base +{ +protected: + // TODO: thread safety! + SvStream& rStream; + +public: + OOutputStreamWrapper(SvStream& _rStream) :rStream(_rStream) { } + +// UNO Anbindung + DECLARE_UNO3_AGG_DEFAULTS(OOutputStreamWrapper, OutputStreamWrapper_Base); + +// 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); + +protected: + /// throws an exception according to the error flag of m_pSvStream + void checkError() const; +}; + +//================================================================== +//= OSeekableOutputStreamWrapper +//================================================================== +typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable + > OSeekableOutputStreamWrapper_Base; +/** helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XOutputStream</type> + which is seekable (i.e. supports the <type scope="com.sun.star.io">XSeekable</type> interface). +*/ +class UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper + :public OOutputStreamWrapper + ,public OSeekableOutputStreamWrapper_Base +{ +public: + OSeekableOutputStreamWrapper(SvStream& _rStream); + + // disambiguate XInterface + 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 (); + + // XSeekable + virtual void SAL_CALL seek( sal_Int64 _nLocation ) 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); +}; + +class UNOTOOLS_DLLPUBLIC OStreamWrapper : public ::cppu::ImplInheritanceHelper3 < OSeekableInputStreamWrapper, com::sun::star::io::XStream, com::sun::star::io::XOutputStream, com::sun::star::io::XTruncate > +{ +public: + OStreamWrapper(SvStream& _rStream); + +// stario::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); + +// 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); + virtual void SAL_CALL truncate() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); +}; + +} +// namespace utl + +#endif // _UTL_STREAM_WRAPPER_HXX_ + diff --git a/unotools/inc/unotools/tempfile.hxx b/unotools/inc/unotools/tempfile.hxx new file mode 100644 index 000000000000..fcd24a20be48 --- /dev/null +++ b/unotools/inc/unotools/tempfile.hxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * 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: tempfile.hxx,v $ + * $Revision: 1.10 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_TEMPFILE_HXX +#define _UNOTOOLS_TEMPFILE_HXX + +#include <tools/string.hxx> +#include <tools/stream.hxx> + +namespace utl +{ + +struct TempFile_Impl; + +/** + The class TempFile gives access to temporary files in the local file system. Sometimes they are needed because a 3rd party + code has a file name based interface, or some file access has to be done locally without transferring tons of bytes to or + from a remote system. + Creating a UCB content on a TempFile is only possible if a UCP for the local file system is present. + TempFiles can always be accessed by SvFileStreams or Sot/SvStorages using the "physical" file name ( not the URL, because + this may be a non-file URL, see below ), but if a UCB content can be created, it is also possible to take the URL and use + the UCB helper classes for streams. For convenience use UcbStreamHelper. + A Tempfile always has a "physical" file name ( a file name in the local computers host notation ) but it has a + "UCB compatible" URL only if a UCP for the local file system exists. This URL may have its own URL scheme + ( not neccessarily "file://" ! ). The TempFile class methods take this into account, but other simple conversions like + the osl functions do not. + So it is a potential error to convert between the filename and the URL of a TempFile object using functions or methods + outside this class. +*/ + +class UNOTOOLS_DLLPUBLIC TempFile +{ + TempFile_Impl* pImp; + sal_Bool bKillingFileEnabled; + +protected: + +public: + /** + Create a temporary file or directory, in the default tempfile folder or if possible in a given folder. + This given folder ( the "parent" parameter ( if not NULL ) ) must be a "UCB compatible" URL. + The temporary object is created in the local file system, even if there is no UCB that can access it. + If the given folder is part of the local file system, the TempFile is created in this folder. + */ + TempFile( const String* pParent=NULL, sal_Bool bDirectory=sal_False ); + + /** + Same as above; additionally the name starts with some given characters followed by a counter ( example: + rLeadingChars="abc" means "abc0","abc1" and so on, depending on existing files in the folder ). + The extension string may be f.e. ".txt" or "", if no extension string is given, ".tmp" is used + */ + TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, + sal_Bool bDirectory=sal_False); + + /** + Same as above; additionally the name starts with some given characters followed by a counter ( example: + rLeadingChars="abc" means "abc0","abc1" and so on, depending on existing files in the folder ). + The extension string may be f.e. ".txt" or "", if no extension string is given, ".tmp" is used + @param _bStartWithZero If set to false names will be generated like "abc","abc0","abc1" + */ + TempFile( const String& rLeadingChars,sal_Bool _bStartWithZero, const String* pExtension=NULL, const String* pParent=NULL,sal_Bool bDirectory=sal_False); + + /** + TempFile will be removed from disk in dtor if EnableKillingTempFile was called before. + Temporary directories will be removed recursively in that case. + */ + ~TempFile(); + + /** + Returns sal_True if it has a valid file name. + */ + sal_Bool IsValid() const; + + /** + Returns the "UCB compatible" URL of the tempfile object. + If you want to have the "physical" file name, use the GetFileName() method of this object, because these + method uses the UCB for the conversion, but never use any external conversion functions for URLs into + "physical" names. + If no UCP is available for the local file system, an empty URL is returned. In this case you can't access + the file as a UCB content ! + */ + String GetURL() const; + + /** + Returns the "physical" name of the tempfile in host notation ( should only be used for 3rd party code + with file name interfaces ). + If you want to have the URL, use the GetURL() method of this object, but never use any external + conversion functions for "physical" names into URLs. + */ + String GetFileName() const; + + /** + Returns a stream to the tempfiles data; the stream is owned by the tempfile object, so you have to keep this + alive as long as you want to use the stream. If the TempFile object is destroyed, it also destroys the + stream object, the underlying file is only deleted if EnableKillingFile( sal_True ) has been called before! + */ + SvStream* GetStream( StreamMode eMode ); + + /** + Let the TempFile object close and destroy the owned stream object if any. + */ + void CloseStream(); + + /** + If enabled the file will be removed from disk when the dtor is called ( default is not enabled ) + */ + void EnableKillingFile( sal_Bool bEnable=sal_True ) + { bKillingFileEnabled = bEnable; } + + sal_Bool IsKillingFileEnabled() const + { return bKillingFileEnabled; } + + /** + Only create a "physical" file name for a temporary file that would be valid at that moment. + Should only be used for 3rd party code with a file name interface that wants to create the file by itself. + If you want to convert file name into a URL, always use class LocalFileHelper, but never use any + conversion functions of osl. + */ + static String CreateTempName( const String* pParent=NULL ); + + /** + The TempNameBaseDirectory is a subfolder in the folder that is passed as a "physical" file name in the + SetTempNameBaseDirectory method. + This subfolder will be used if a TempFile or TempName is created without a parent name or a parent name + that does not belong to the local file system. + The caller of the SetTempNameBase is responsible for deleting this folder and all temporary files in it. + The return value of both methods is the complete "physical" name of the tempname base folder. + It is not a URL because alle URLs must be "UCB compatible", so there may be no suitable URL at all. + */ + static String SetTempNameBaseDirectory( const String &rBaseName ); + static String GetTempNameBaseDirectory(); +}; + +} + +#endif diff --git a/unotools/inc/unotools/textsearch.hxx b/unotools/inc/unotools/textsearch.hxx new file mode 100644 index 000000000000..cbcaa9829674 --- /dev/null +++ b/unotools/inc/unotools/textsearch.hxx @@ -0,0 +1,199 @@ +/************************************************************************* + * + * 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: textsearch.hxx,v $ + * $Revision: 1.11 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_TEXTSEARCH_HXX +#define _UNOTOOLS_TEXTSEARCH_HXX +#include <i18npool/lang.h> +#include <tools/string.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/util/XTextSearch.hpp> +#include <com/sun/star/util/SearchOptions.hpp> + +// Forward-Deklaration +class CharClass; + +namespace com { + namespace sun { + namespace star { + namespace util { + struct SearchResult; + } + } + } +} + +// ............................................................................ +namespace utl +{ +// ............................................................................ + +// SS - Klasse fuers Suchen +class UNOTOOLS_DLLPUBLIC SearchParam +{ +public: + enum SearchType{ SRCH_NORMAL, SRCH_REGEXP, SRCH_LEVDIST }; + +private: + String sSrchStr; // the search string + String sReplaceStr; // the replace string + + SearchType eSrchType; // search normal/regular/LevDist + + int bWordOnly : 1; // used by normal search + int bSrchInSel : 1; // search only in the selection + int bCaseSense : 1; // + + // values for the "weight Levenshtein-Distance" + int bLEV_Relaxed : 1; + int nLEV_OtherX; + int nLEV_ShorterY; + int nLEV_LongerZ; + + // asian flags - used for the transliteration + long nTransliterationFlags; + +public: + SearchParam( const String &rText, + SearchType eSrchType = SearchParam::SRCH_NORMAL, + BOOL bCaseSens = TRUE, + BOOL bWrdOnly = FALSE, + BOOL bSrchInSel = FALSE ); + SearchParam( const SearchParam& ); + + const String& GetSrchStr() const { return sSrchStr; } + const String& GetReplaceStr() const { return sReplaceStr; } + SearchType GetSrchType() const { return eSrchType; } + + int IsCaseSensitive() const { return bCaseSense; } + int IsSrchInSelection() const { return bSrchInSel; } + int IsSrchWordOnly() const { return bWordOnly; } + + + void SetSrchStr( const String& rStr ) { sSrchStr = rStr; } + void SetReplaceStr( const String& rStr ) { sReplaceStr = rStr; } + void SetSrchType( SearchType eType ) { eSrchType = eType; } + + void SetCaseSensitive( int bFlag ) { bCaseSense = bFlag; } + void SetSrchInSelection( int bFlag ) { bSrchInSel = bFlag; } + void SetSrchWordOnly( int bFlag ) { bWordOnly = bFlag; } + + int IsSrchRelaxed() const { return bLEV_Relaxed; } + int GetLEVOther() const { return nLEV_OtherX; } + int GetLEVShorter() const { return nLEV_ShorterY; } + int GetLEVLonger() const { return nLEV_LongerZ; } + + void SetSrchRelaxed( int bFlag ) { bLEV_Relaxed = bFlag; } + void SetLEVOther( int nValue ) { nLEV_OtherX = nValue; } + void SetLEVShorter( int nValue ) { nLEV_ShorterY = nValue; } + void SetLEVLonger( int nValue ) { nLEV_LongerZ = nValue; } + + long GetTransliterationFlags() const { return nTransliterationFlags; } + void SetTransliterationFlags( long nValue ) { nTransliterationFlags = nValue; } +}; + +// Klasse zum Suchen eines Strings in einem String. +// Unterstuetzt werden folgende Verfahren: +// - normalen Text (Bayer/Moore) +// - regulaere Ausdruecke +// - gewichtete Levenshtein Distanz +// +// Es kann Vorwaerts und Rueckwaerts gesucht werden! + +class UNOTOOLS_DLLPUBLIC TextSearch +{ + struct CachedTextSearch + { + ::osl::Mutex mutex; + ::com::sun::star::util::SearchOptions Options; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XTextSearch > xTextSearch; + }; + + static CachedTextSearch maCache; + + static ::com::sun::star::uno::Reference< ::com::sun::star::util::XTextSearch > + getXTextSearch( const ::com::sun::star::util::SearchOptions& rPara ); + + com::sun::star::uno::Reference < com::sun::star::util::XTextSearch > + xTextSearch; + + void Init( const SearchParam & rParam, + const ::com::sun::star::lang::Locale& rLocale ); + +public: + // rText ist der zusuchende String + // this first two CTORs are deprecated! + TextSearch( const SearchParam & rPara, LanguageType nLanguage ); + TextSearch( const SearchParam & rPara, const CharClass& rCClass ); + + TextSearch( const ::com::sun::star::util::SearchOptions& rPara ); + ~TextSearch(); + + /* search in the (selected) text the search string: + rScrTxt - the text, in in which we search + pStart - start position for the search + pEnde - end position for the search + + RETURN values == TRUE: something is found + - pStart start pos of the found text, + - pStart end pos of the found text, + - pSrchResult - the search result with all found + positions. Is only filled with more positions + if the regular expression handles groups. + + == FALSE: nothing found, pStart,pEnde unchanged. + + Definitions: start pos always inclusive, end pos always exclusive! + The position must always in the right direction! + search forward: start <= end + search backward: end <= start + */ + int SearchFrwrd( const String &rStr, + xub_StrLen* pStart, xub_StrLen* pEnde, + ::com::sun::star::util::SearchResult* pSrchResult = 0 ); + int SearchBkwrd( const String &rStr, + xub_StrLen* pStart, xub_StrLen* pEnde, + ::com::sun::star::util::SearchResult* pSrchResult = 0 ); + + void SetLocale( const ::com::sun::star::util::SearchOptions& rOpt, + const ::com::sun::star::lang::Locale& rLocale ); + + /* replace back references in the replace string by the sub expressions from the search result */ + void ReplaceBackReferences( String& rReplaceStr, const String &rStr, const ::com::sun::star::util::SearchResult& rResult ); + +}; + +// ............................................................................ +} // namespace utl +// ............................................................................ + +#endif + diff --git a/unotools/inc/unotools/transliterationwrapper.hxx b/unotools/inc/unotools/transliterationwrapper.hxx new file mode 100644 index 000000000000..3c5baf56b801 --- /dev/null +++ b/unotools/inc/unotools/transliterationwrapper.hxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * 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: transliterationwrapper.hxx,v $ + * $Revision: 1.15 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#define _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#include <tools/string.hxx> +#include <tools/solar.h> +#include <com/sun/star/i18n/XExtendedTransliteration.hpp> + +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + +namespace utl +{ + +class UNOTOOLS_DLLPUBLIC TransliterationWrapper +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + ::com::sun::star::uno::Reference< + ::com::sun::star::i18n::XExtendedTransliteration > xTrans; + ::com::sun::star::lang::Locale aLocale; + sal_uInt32 nType; + sal_uInt16 nLanguage; + mutable sal_Bool bFirstCall; + + // not implemented, prevent usage + TransliterationWrapper( const TransliterationWrapper& ); + TransliterationWrapper& operator=( const TransliterationWrapper& ); + + void loadModuleImpl() const; + void setLanguageLocaleImpl( sal_uInt16 nLang ); + +public: + TransliterationWrapper( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & xSF, + sal_uInt32 nType ); + + ~TransliterationWrapper(); + + // get current Locale / Language + const ::com::sun::star::lang::Locale& getLocale() const { return aLocale;} + sal_uInt16 getLanguage() const { return nLanguage; } + + sal_uInt32 getType() const { return nType; } + + sal_Bool needLanguageForTheMode() const; + + /** set a new language and load the corresponding transliteration module if + needed for the mode set with nType in the ctor */ + void loadModuleIfNeeded( sal_uInt16 nLang ); + + /** Load the transliteration module specified by rModuleName, which has to + be the UNO service implementation name that is expanded to the full UNO + service implementation name, for example, "NumToCharKanjiShort_ja_JP" + expands to + "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP". + @ATTENTION! + This method ignores the mode type set with the constructor and + interferes with the loadModuleIfNeeded() method and the transliterate() + method that gets a LanguageType passed as parameter. Using one of + those may load a different module and overwrite this setting. Only the + transliterate() method that takes no LanguageType parameter may be used + for a specific module loaded with this method. */ + void loadModuleByImplName( const String& rModuleName, sal_uInt16 nLang ); + + /** This transliteration method corresponds with the loadModuleByImplName() + method. It relies on a module being loaded and does not try load one. + If for any reason the string can't be transliterated the original + string is returned. */ + String transliterate( const String& rStr, + xub_StrLen nStart, xub_StrLen nLen, + ::com::sun::star::uno::Sequence <sal_Int32>* pOffset ) const; + + // Wrapper implementations of class Transliteration + String transliterate( const String& rStr, sal_uInt16 nLanguage, + xub_StrLen nStart, xub_StrLen nLen, + ::com::sun::star::uno::Sequence <sal_Int32>* pOffset ); + + /** If two strings are equal per this transliteration. + Returns the number of matched code points in any case, even if strings + are not equal, for example: + equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 ) + returns false and nMatch:=1 and nMatch2:=1 + equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 ) + returns false and nMatch:=2 and nMatch2:=2 + */ + sal_Bool equals( + const String& rStr1, sal_Int32 nPos1, sal_Int32 nCount1, sal_Int32& nMatch1, + const String& rStr2, sal_Int32 nPos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) const; + + sal_Int32 compareSubstring( + const String& rStr1, sal_Int32 nOff1, sal_Int32 nLen1, + const String& rStr2, sal_Int32 nOff2, sal_Int32 nLen2 ) const; + + sal_Int32 compareString( const String& rStr1, const String& rStr2 ) const; + + + // helpers + + /** If two strings are really equal as per this translation, and not just + one string is matching the start of the other. Use this method instead + of compareString()==0 because it is much faster. + */ + sal_Bool isEqual( const String& rStr1, const String& rStr2 ) const; + + /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa" + */ + sal_Bool isMatch( const String& rStr1, const String& rStr2 ) const; + +}; + +// ............................................................................ +} // namespace utl +// ............................................................................ + +#endif diff --git a/unotools/inc/unotools/ucbhelper.hxx b/unotools/inc/unotools/ucbhelper.hxx new file mode 100644 index 000000000000..59536df150c0 --- /dev/null +++ b/unotools/inc/unotools/ucbhelper.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * 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: ucbhelper.hxx,v $ + * $Revision: 1.11 $ + * + * 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 "unotools/unotoolsdllapi.h" + +#ifndef _UNOTOOLS_UCBHELPER_HXX +#define _UNOTOOLS_UCBHELPER_HXX + +// include --------------------------------------------------------------- +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/ucb/NameClash.hpp> +#include <com/sun/star/ucb/XContentProvider.hpp> + +#include <tools/string.hxx> + +namespace ucbhelper +{ + class Content; +} + +namespace utl +{ + class UNOTOOLS_DLLPUBLIC UCBContentHelper + { + private: + static sal_Bool Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData, + sal_Int32 nNameClash ); + + public: + static sal_Bool IsDocument( const String& rContent ); + static sal_Bool IsFolder( const String& rContent ); + static sal_Bool GetTitle( const String& rContent, String& rTitle ); + static sal_Bool Kill( const String& rContent ); + + static ::com::sun::star::uno::Any GetProperty( const String& rURL, const ::rtl::OUString& rName ); + + static ::com::sun::star::uno::Sequence< ::rtl::OUString > + GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted = sal_False ); + static ::com::sun::star::uno::Sequence< ::rtl::OUString > GetResultSet( const String& rURL ); + + static sal_Bool CopyTo( const String& rSource, const String& rDest ); + static sal_Bool MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash = com::sun::star::ucb::NameClash::ERROR ); + + static sal_Bool CanMakeFolder( const String& rFolder ); + static sal_Bool MakeFolder( const String& rFolder, sal_Bool bNewOnly = sal_False ); + static sal_Bool MakeFolder( ::ucbhelper::Content& rParent, + const String& rTitle, + ::ucbhelper::Content& rNewFolder, + sal_Bool bNewOnly = sal_False ); + static sal_Bool HasParentFolder( const String& rFolder ); + + static ULONG GetSize( const String& rContent ); + static sal_Bool IsYounger( const String& rIsYoung, const String& rIsOlder ); + + static sal_Bool Exists( const String& rContent ); + static sal_Bool FindInPath( const String& rPath, const String& rName, String& rFile, char cDelim = ';', BOOL bAllowWildCards = TRUE ); + static sal_Bool Find( const String& rFolder, const String& rName, String& rFile, BOOL bAllowWildCards = FALSE ); + static sal_Bool IsSubPath( const ::rtl::OUString& rPath, const ::rtl::OUString& rChildCandidate, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProvider >& xContentProvider = ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProvider >() ); + }; +} + +#endif + + diff --git a/unotools/inc/unotools/ucblockbytes.hxx b/unotools/inc/unotools/ucblockbytes.hxx new file mode 100644 index 000000000000..5600cfdb16f4 --- /dev/null +++ b/unotools/inc/unotools/ucblockbytes.hxx @@ -0,0 +1,225 @@ +/************************************************************************* + * + * 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: ucblockbytes.hxx,v $ + * $Revision: 1.27 $ + * + * 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 _UNTOOLS_UCBLOCKBYTES_HXX +#define _UNTOOLS_UCBLOCKBYTES_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/ucb/XContent.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include "unotools/unotoolsdllapi.h" + +#include <vos/thread.hxx> +#include <vos/conditn.hxx> +#include <vos/mutex.hxx> +#include <tools/stream.hxx> +#include <tools/link.hxx> +#include <tools/errcode.hxx> +#include <tools/datetime.hxx> + +namespace com +{ + namespace sun + { + namespace star + { + namespace task + { + class XInteractionHandler; + } + namespace io + { + class XStream; + class XInputStream; + class XOutputStream; + class XSeekable; + } + namespace ucb + { + class XContent; + } + namespace beans + { + struct PropertyValue; + } + } + } +} + +namespace utl +{ +SV_DECL_REF( UcbLockBytes ) + +class UcbLockBytesHandler : public SvRefBase +{ + sal_Bool m_bActive; +public: + enum LoadHandlerItem + { + DATA_AVAILABLE, + DONE, + CANCEL + }; + + UcbLockBytesHandler() + : m_bActive( sal_True ) + {} + + virtual void Handle( LoadHandlerItem nWhich, UcbLockBytesRef xLockBytes ) = 0; + void Activate( BOOL bActivate = sal_True ) { m_bActive = bActivate; } + sal_Bool IsActive() const { return m_bActive; } +}; + +SV_DECL_IMPL_REF( UcbLockBytesHandler ) + +#define NS_UNO ::com::sun::star::uno +#define NS_IO ::com::sun::star::io +#define NS_UCB ::com::sun::star::ucb +#define NS_BEANS ::com::sun::star::beans +#define NS_TASK ::com::sun::star::task + +class UNOTOOLS_DLLPUBLIC UcbLockBytes : public virtual SvLockBytes +{ + vos::OCondition m_aInitialized; + vos::OCondition m_aTerminated; + vos::OMutex m_aMutex; + + String m_aContentType; + String m_aRealURL; + DateTime m_aExpireDate; + + NS_UNO::Reference < NS_IO::XInputStream > m_xInputStream; + NS_UNO::Reference < NS_IO::XOutputStream > m_xOutputStream; + NS_UNO::Reference < NS_IO::XSeekable > m_xSeekable; + void* m_pCommandThread; // is alive only for compatibility reasons + UcbLockBytesHandlerRef m_xHandler; + + sal_uInt32 m_nRead; + sal_uInt32 m_nSize; + ErrCode m_nError; + + sal_Bool m_bTerminated : 1; + sal_Bool m_bDontClose : 1; + sal_Bool m_bStreamValid : 1; + + DECL_LINK( DataAvailHdl, void * ); + + UcbLockBytes( UcbLockBytesHandler* pHandler=NULL ); +protected: + virtual ~UcbLockBytes (void); + +public: + // properties: Referer, PostMimeType + static UcbLockBytesRef CreateLockBytes( const NS_UNO::Reference < NS_UCB::XContent >& xContent, + const ::rtl::OUString& rReferer, + const ::rtl::OUString& rMediaType, + const NS_UNO::Reference < NS_IO::XInputStream >& xPostData, + const NS_UNO::Reference < NS_TASK::XInteractionHandler >& xInter, + UcbLockBytesHandler* pHandler=0 ); + + static UcbLockBytesRef CreateLockBytes( const NS_UNO::Reference < NS_UCB::XContent >& xContent, + const NS_UNO::Sequence < NS_BEANS::PropertyValue >& rProps, + StreamMode eMode, + const NS_UNO::Reference < NS_TASK::XInteractionHandler >& xInter, + UcbLockBytesHandler* pHandler=0 ); + + static UcbLockBytesRef CreateInputLockBytes( const NS_UNO::Reference < NS_IO::XInputStream >& xContent ); + static UcbLockBytesRef CreateLockBytes( const NS_UNO::Reference < NS_IO::XStream >& xContent ); + + // SvLockBytes + virtual void SetSynchronMode (BOOL bSynchron); + virtual ErrCode ReadAt ( ULONG nPos, void *pBuffer, ULONG nCount, ULONG *pRead) const; + virtual ErrCode WriteAt ( ULONG, const void*, ULONG, ULONG *pWritten); + virtual ErrCode Flush (void) const; + virtual ErrCode SetSize (ULONG); + virtual ErrCode Stat ( SvLockBytesStat *pStat, SvLockBytesStatFlag) const; + + void SetError( ErrCode nError ) + { m_nError = nError; } + + ErrCode GetError() const + { return m_nError; } + + void Cancel(); // is alive only for compatibility reasons + + // the following properties are available when and after the first DataAvailable callback has been executed + String GetContentType() const; + String GetRealURL() const; + DateTime GetExpireDate() const; + + // calling this method delegates the responsibility to call closeinput to the caller! + NS_UNO::Reference < NS_IO::XInputStream > getInputStream(); + NS_UNO::Reference < NS_IO::XStream > getStream(); + +#if _SOLAR__PRIVATE + sal_Bool setInputStream_Impl( const NS_UNO::Reference < NS_IO::XInputStream > &rxInputStream, + sal_Bool bSetXSeekable = sal_True ); + sal_Bool setStream_Impl( const NS_UNO::Reference < NS_IO::XStream > &rxStream ); + void terminate_Impl (void); + + NS_UNO::Reference < NS_IO::XInputStream > getInputStream_Impl() const + { + vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); + return m_xInputStream; + } + + NS_UNO::Reference < NS_IO::XOutputStream > getOutputStream_Impl() const + { + vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); + return m_xOutputStream; + } + + NS_UNO::Reference < NS_IO::XSeekable > getSeekable_Impl() const + { + vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); + return m_xSeekable; + } + + sal_Bool hasInputStream_Impl() const + { + vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); + return m_xInputStream.is(); + } + + void setDontClose_Impl() + { m_bDontClose = sal_True; } + + void SetContentType_Impl( const String& rType ) { m_aContentType = rType; } + void SetRealURL_Impl( const String& rURL ) { m_aRealURL = rURL; } + void SetExpireDate_Impl( const DateTime& rDateTime ) { m_aExpireDate = rDateTime; } + void SetStreamValid_Impl(); +#endif +}; + +SV_IMPL_REF( UcbLockBytes ); + +} + +#endif diff --git a/unotools/inc/unotools/ucbstreamhelper.hxx b/unotools/inc/unotools/ucbstreamhelper.hxx new file mode 100644 index 000000000000..4bc9686ff587 --- /dev/null +++ b/unotools/inc/unotools/ucbstreamhelper.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * 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: ucbstreamhelper.hxx,v $ + * $Revision: 1.11 $ + * + * 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 _UNTOOLS_UCBSTREAMHELPER_HXX +#define _UNTOOLS_UCBSTREAMHELPER_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XStream.hpp> +#include "unotools/unotoolsdllapi.h" + +#include <tools/stream.hxx> + +namespace com +{ + namespace sun + { + namespace star + { + namespace task + { + class XInteractionHandler; + } + namespace io + { + class XStream; + class XInputStream; + } + } + } +} + +#define NS_UNO ::com::sun::star::uno +#define NS_IO ::com::sun::star::io +#define NS_TASK ::com::sun::star::task + +class String; +namespace utl +{ + class UcbLockBytesHandler; + + class UNOTOOLS_DLLPUBLIC UcbStreamHelper : public SvStream + { + public: + static SvStream* CreateStream( const String& rFileName, StreamMode eOpenMode, + UcbLockBytesHandler* pHandler=0, sal_Bool bForceSynchron=sal_True ); + static SvStream* CreateStream( const String& rFileName, StreamMode eOpenMode, + NS_UNO::Reference < NS_TASK::XInteractionHandler >, + UcbLockBytesHandler* pHandler=0, sal_Bool bForceSynchron=sal_True ); + static SvStream* CreateStream( const String& rFileName, StreamMode eOpenMode, + sal_Bool bFileExists, + UcbLockBytesHandler* pHandler=0, sal_Bool bForceSynchron=sal_True ); + static SvStream* CreateStream( NS_UNO::Reference < NS_IO::XInputStream > xStream ); + static SvStream* CreateStream( NS_UNO::Reference < NS_IO::XStream > xStream ); + static SvStream* CreateStream( NS_UNO::Reference < NS_IO::XInputStream > xStream, sal_Bool bCloseStream ); + static SvStream* CreateStream( NS_UNO::Reference < NS_IO::XStream > xStream, sal_Bool bCloseStream ); + }; +} + +#endif diff --git a/unotools/inc/unotools/unotoolsdllapi.h b/unotools/inc/unotools/unotoolsdllapi.h new file mode 100644 index 000000000000..6aefb84432ec --- /dev/null +++ b/unotools/inc/unotools/unotoolsdllapi.h @@ -0,0 +1,44 @@ +/************************************************************************* + * + * 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: unotoolsdllapi.h,v $ + * $Revision: 1.4 $ + * + * 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_UNOTOOLSDLLAPI_H +#define INCLUDED_UNOTOOLSDLLAPI_H + +#include "sal/types.h" + +#if defined(UNOTOOLS_DLLIMPLEMENTATION) +#define UNOTOOLS_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define UNOTOOLS_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define UNOTOOLS_DLLPRIVATE SAL_DLLPRIVATE + +#endif /* INCLUDED_UNOTOOLSDLLAPI_H */ + diff --git a/unotools/inc/unotools/unotunnelhelper.hxx b/unotools/inc/unotools/unotunnelhelper.hxx new file mode 100644 index 000000000000..cfe6084577e6 --- /dev/null +++ b/unotools/inc/unotools/unotunnelhelper.hxx @@ -0,0 +1,199 @@ +/************************************************************************* + * + * 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: unotunnelhelper.hxx,v $ + * $Revision: 1.4 $ + * + * 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 _UNOTOOLS_UNOTUNNELHLP_HXX +#define _UNOTOOLS_UNOTUNNELHLP_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <rtl/uuid.h> +#include <rtl/memory.h> + +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +namespace utl +{ +namespace staruno = ::com::sun::star::uno; +namespace starlang = ::com::sun::star::lang; + +//----------------------------------------------------------------------------------------------------------- +// to use the following, define +// sal_Bool getTunneledImplementation(Classname*& pObjImpl, staruno::Reference<starlang::XUnoTunnel> const& xObj); + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, staruno::Reference<starlang::XUnoTunnel> const& xTunnel) + throw(staruno::RuntimeException) +{ + if (xTunnel.is()) + return getTunneledImplementation(pImpl, xTunnel); + + pImpl = 0; + return sal_False; +} + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, staruno::Reference<staruno::XInterface> const& xObj) + throw(staruno::RuntimeException) +{ + staruno::Reference<starlang::XUnoTunnel> xTunnel(xObj,staruno::UNO_QUERY); + if (xTunnel.is()) + return getTunneledImplementation(pImpl, xTunnel); + + pImpl = 0; + return sal_False; +} + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, staruno::Any const& aObj) + throw(staruno::RuntimeException) +{ + staruno::Reference<starlang::XUnoTunnel> xTunnel; + if (cppu::extractInterface(xTunnel, aObj)) + getTunneledImplementation(pImpl, xTunnel); + + pImpl = 0; + return sal_False; +} + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, starlang::XUnoTunnel* pObj) + throw(staruno::RuntimeException) +{ + if (pObj) + { + staruno::Reference<starlang::XUnoTunnel> xTunnel(pObj); + return getTunneledImplementation(pImpl, xTunnel); + } + + pImpl = 0; + return sal_False; +} + +//----------------------------------------------------------------------------------------------------------- + +class UnoTunnelId +{ + sal_Int8 tunnelId[16]; +public: + UnoTunnelId(sal_Bool bUseMAC = sal_True) throw() + { + rtl_createUuid(reinterpret_cast<sal_uInt8*>(tunnelId),0,bUseMAC); + } + + staruno::Sequence<sal_Int8> getId() const throw(staruno::RuntimeException) + { + return staruno::Sequence<sal_Int8>(tunnelId, sizeof(tunnelId)); + } + + sal_Bool equalTo(staruno::Sequence<sal_Int8> const& rIdentifier) throw() + { + return rIdentifier.getLength() == sizeof(tunnelId) && + rtl_compareMemory(tunnelId, rIdentifier.getConstArray(), sizeof(tunnelId)) == 0; + } + + sal_Int8 const (&getIdBytes() const)[16] { return tunnelId; } +}; + +//----------------------------------------------------------------------------------------------------------- +template<class Classname> +class UnoTunnelImplBase +{ +protected: + Classname* ThisImplementation() throw() { return static_cast<Classname*>(this); } + + sal_Int64 makeUnoSomething() throw() + { + return reinterpret_cast<sal_Int64>(static_cast<void*>(ThisImplementation())); + } + + static Classname* extractUnoSomething(sal_Int64 nSomething) throw() + { + if (nSomething != sal_Int64()) + return static_cast<Classname*>(reinterpret_cast<void*>(nSomething)); + + return NULL; + } +#ifdef LINUX +public: +#endif + static Classname* + extractUnoSomething( + staruno::Reference<starlang::XUnoTunnel> const& xObj, + staruno::Sequence<sal_Int8> const& rMyTunnelId + ) + throw(staruno::RuntimeException) + { + return xObj.is() ? extractUnoSomething(xObj->getSomething(rMyTunnelId)) : NULL; + } +}; +//----------------------------------------------------------------------------------------------------------- + + +template<class Classname> +class UnoTunnelHelper : public UnoTunnelImplBase<Classname> +{ +protected: + static UnoTunnelId s_aTunnelId; + + sal_Int64 getSomething(staruno::Sequence<sal_Int8> const& rTunnelId) throw() + { + if (s_aTunnelId.equalTo(rTunnelId)) + return this->makeUnoSomething(); + else + return sal_Int64(); + } +public: + static staruno::Sequence<sal_Int8> getImplementationTunnelId() + throw(staruno::RuntimeException) + { + return s_aTunnelId.getId(); + } +#ifndef LINUX + friend sal_Bool getTunneledImplementation(Classname*& pImpl, staruno::Reference<starlang::XUnoTunnel> const& xObj) + throw(staruno::RuntimeException) + { + pImpl = UnoTunnelHelper<Classname>::UnoTunnelHelper<Classname>::extractUnoSomething( xObj, UnoTunnelHelper<Classname>::getImplementationTunnelId() ); + + return pImpl != 0; + } +#endif +}; +template<class Classname> +UnoTunnelId UnoTunnelHelper<Classname>::s_aTunnelId; + + +//----------------------------------------------------------------------------------------------------------- +} // namespace utl + +#endif // _UNOTOOLS_UNOTUNNELHLP_HXX + |