diff options
author | Frank Schönheit <fs@openoffice.org> | 2000-09-29 10:28:15 +0000 |
---|---|---|
committer | Frank Schönheit <fs@openoffice.org> | 2000-09-29 10:28:15 +0000 |
commit | b83bbfa982ec0bdf93fb96e515ba7e2d053d66e8 (patch) | |
tree | 0bfac8a4080bca433ec6e3892dd3f4c1142593c9 | |
parent | dc8ad513eb9af14c133c8984081196eea2df5839 (diff) |
initial import
48 files changed, 9791 insertions, 0 deletions
diff --git a/comphelper/inc/comphelper/basicio.hxx b/comphelper/inc/comphelper/basicio.hxx new file mode 100644 index 000000000000..616ea0850b35 --- /dev/null +++ b/comphelper/inc/comphelper/basicio.hxx @@ -0,0 +1,143 @@ +/************************************************************************* + * + * $RCSfile: basicio.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_BASIC_IO_HXX_ +#define _COMPHELPER_BASIC_IO_HXX_ + +#ifndef _COM_SUN_STAR_IO_XPERSISTOBJECT_HPP_ +#include <com/sun/star/io/XPersistObject.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_ +#include <com/sun/star/awt/FontDescriptor.hpp> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +namespace stario = ::com::sun::star::io; +namespace staruno = ::com::sun::star::uno; +namespace starawt = ::com::sun::star::awt; + +// sal_Bool +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Bool& _rVal); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Bool _bVal); + +// ::rtl::OUString +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, ::rtl::OUString& _rStr); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const ::rtl::OUString& _rStr); + +// sal_Int16 +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int16& _rValue); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int16 _nValue); + +// sal_uInt16 +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt16& _rValue); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt16 _nValue); + +// sal_uInt32 +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt32& _rValue); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt32 _nValue); + +// sal_Int16 +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int32& _rValue); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int32 _nValue); + +// FontDescriptor +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& InStream, starawt::FontDescriptor& rVal); +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& OutStream, const starawt::FontDescriptor& rVal); + +// sequences +template <class ELEMENT> +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, staruno::Sequence<ELEMENT>& _rSeq) +{ + sal_Int32 nLen = _rxInStream->readLong(); + _rSeq.realloc(nLen); + if (nLen) + { + ELEMENT* pElement = _rSeq.getArray(); + for (sal_Int32 i=0; i<nLen; ++i, ++pElement) + _rxInStream >> *pElement; + } + return _rxInStream; +} + +template <class ELEMENT> +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const staruno::Sequence<ELEMENT>& _rSeq) +{ + sal_Int32 nLen = _rSeq.getLength(); + _rxOutStream->writeLong(nLen); + if (nLen) + { + const ELEMENT* pElement = _rSeq.getConstArray(); + for (sal_Int32 i = 0; i < nLen; ++i, ++pElement) + _rxOutStream << *pElement; + } + return _rxOutStream; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_BASIC_IO_HXX_ + diff --git a/comphelper/inc/comphelper/componentfactory.hxx b/comphelper/inc/comphelper/componentfactory.hxx new file mode 100644 index 000000000000..8caf7cbe5e83 --- /dev/null +++ b/comphelper/inc/comphelper/componentfactory.hxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * $RCSfile: componentfactory.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_COMPONENTFACTORY_HXX +#define _COMPHELPER_COMPONENTFACTORY_HXX + + +/** + * @Descr + * Utilities to get an instance of a component if a ProcessServiceFactory + * is not available like it is the case in "small tools" as the Setup. + */ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif + + +#define LLCF_DOSTRING( x ) #x +#define LLCF_STRING( x ) LLCF_DOSTRING( x ) +#ifdef UNX +// "libNAME603xy.so" (__DLLEXTENSION == "xy.so") +#define LLCF_LIBNAME( name ) "lib" name LLCF_STRING( SUPD ) __DLLEXTENSION +#else +// "NAME603xy.dll" (__DLLEXTENSION == "xy") +#define LLCF_LIBNAME( name ) name LLCF_STRING( SUPD ) __DLLEXTENSION ".dll" +#endif + + +namespace rtl { + class OUString; +} +namespace com { namespace sun { namespace star { + namespace uno { + class XInterface; + } + namespace lang { + class XSingleServiceFactory; + class XMultiServiceFactory; + } + namespace registry { + class XRegistryKey; + } +}}} + + +namespace comphelper +{ + +/** + * Get an instance of the component <code>rImplementationName</code> located + * in library <code>rLibraryName</code>. The instance must then be queried + * for the desired interface with a queryInterface call. + * The library name must be constructed with the macro + * <code>LLCF_LIBNAME( name )</code> if it is a library from the normal build + * process which includes build number and platform name. + * + * @example:C++ + * <listing> + + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + Reference< whatever::XYourComponent > xComp; + // library name, e.g. xyz603mi.dll or libxyz603.so + ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( "xyz" ) ) ); + ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.whatever.YourComponent" ) ); + Reference< Xinterface > xI = ::comphelper::getComponentInstance( aLibName, aImplName ); + if ( xI.is() ) + { + Any x = xI->queryInterface( ::getCppuType((const Reference< whatever::XYourComponent >*)0) ); + x >>= xComp; + } + if ( !xComp.is() ) + // you're lost + + * </listing> + */ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + getComponentInstance( + const ::rtl::OUString & rLibraryName, + const ::rtl::OUString & rImplementationName + ); + + +::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > + loadLibComponentFactory( + const ::rtl::OUString & rLibraryName, + const ::rtl::OUString & rImplementationName, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > & xKey + ); + + +} // namespace comphelper + +#endif // _COMPHELPER_COMPONENTFACTORY_HXX diff --git a/comphelper/inc/comphelper/container.hxx b/comphelper/inc/comphelper/container.hxx new file mode 100644 index 000000000000..98fb999e6b29 --- /dev/null +++ b/comphelper/inc/comphelper/container.hxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * $RCSfile: container.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_CONTAINER_HXX_ +#define _COMPHELPER_CONTAINER_HXX_ + +#ifndef __SGI_STL_VECTOR +#include <stl/vector> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +#define NOTIFY_LISTENERS(listeners, XIface, method, evt) \ + if (listeners.getLength()) \ + { \ + ::cppu::OInterfaceIteratorHelper aIter(listeners); \ + while (aIter.hasMoreElements()) \ + reinterpret_cast< XIface* >(aIter.next())->method(evt); \ + } + +//======================================================================== +//= IndexAccessIterator +//======================================================================== +/** ein Iterator, der von einem XIndexAccess ausgehend alle Elemente durchiteriert (pre-order) +*/ +class IndexAccessIterator +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> m_xStartingPoint; + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> m_xCurrentObject; + // das aktuelle Objekt + ::std::vector<sal_Int32> m_arrChildIndizies; + // ich bewege mich eigentlich durch einen Baum, dummerweise haben dessen + // Elemente aber kein GetNextSibling, also muss ich mir merken, wo die Childs + // innerhalb ihres Parents sitzen (das ist sozusagen der Pfad von der Wurzel + // zu m_xCurrentObject + + ::rtl::OUString m_ustrProperty; + // der Name der gesuchten property + +public: + IndexAccessIterator(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xStartingPoint); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> Next(); + + virtual void Invalidate() { m_xCurrentObject = NULL; } + +protected: + virtual sal_Bool ShouldHandleElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& rElement) { return sal_True; } + // damit kann man bestimmte Elemente ausschliessen, die werden dann einfach + // uebergangen + // wenn hier sal_True zurueckkommt, wird dieses Element von Next zurueckgeliefert, man kann sich hier also auch + // gleich ein paar zusaetzliche Angaben zu dem Element holen (deswegen ist die Methode auch nicht const) + virtual sal_Bool ShouldStepInto(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xContainer) const { return sal_True; } +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_CONTAINER_HXX_ + + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * + * Revision 1.0 29.09.00 09:01:05 fs + ************************************************************************/ + diff --git a/comphelper/inc/comphelper/enumhelper.hxx b/comphelper/inc/comphelper/enumhelper.hxx new file mode 100644 index 000000000000..79a465aa49f9 --- /dev/null +++ b/comphelper/inc/comphelper/enumhelper.hxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * $RCSfile: enumhelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_ENUMHELPER_HXX_ +#define _COMPHELPER_ENUMHELPER_HXX_ + +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATION_HPP_ +#include <com/sun/star/container/XEnumeration.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_ +#include <com/sun/star/container/XIndexAccess.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace starcontainer = ::com::sun::star::container; + namespace staruno = ::com::sun::star::uno; + namespace starlang = ::com::sun::star::lang; + +//================================================================== +//= OEnumerationByName +//================================================================== +/** provides an <type scope="com.sun.star.container">XEnumeration</type> access based + on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface +*/ +class OEnumerationByName : public ::cppu::WeakImplHelper1<starcontainer::XEnumeration> +{ + staruno::Sequence< ::rtl::OUString> m_aNames; + sal_Int32 m_nPos; + staruno::Reference<starcontainer::XNameAccess> m_xAccess; + +public: + OEnumerationByName(const staruno::Reference<starcontainer::XNameAccess>& _rxAccess) + :m_aNames(_rxAccess->getElementNames()) + ,m_nPos(0) + ,m_xAccess(_rxAccess) + { + } + + virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); + virtual staruno::Any SAL_CALL nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); +}; + +//================================================================== +//= OEnumerationByIndex +//================================================================== +/** provides an <type scope="com.sun.star.container">XEnumeration</type> access based + on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface +*/ +class OEnumerationByIndex : public ::cppu::WeakImplHelper1<starcontainer::XIndexAccess> +{ + sal_Int32 m_nPos; + staruno::Reference<starcontainer::XIndexAccess> m_xAccess; + +public: + OEnumerationByIndex(const staruno::Reference<starcontainer::XIndexAccess>& _rxAccess) + :m_xAccess(_rxAccess) + ,m_nPos(0) + { + } + + virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); + virtual staruno::Any SAL_CALL nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); +}; + +//......................................................................... +} +//... namespace comphelper ....................................................... + +#endif // _COMPHELPER_ENUMHELPER_HXX_ + + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * + * Revision 1.0 29.09.00 08:49:14 fs + ************************************************************************/ + diff --git a/comphelper/inc/comphelper/eventattachermgr.hxx b/comphelper/inc/comphelper/eventattachermgr.hxx new file mode 100644 index 000000000000..157352c0d2c4 --- /dev/null +++ b/comphelper/inc/comphelper/eventattachermgr.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * $RCSfile: eventattachermgr.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_EVENTATTACHERMGR_HXX_ +#define _COMPHELPER_EVENTATTACHERMGR_HXX_ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif + +namespace com { namespace sun { namespace star { +namespace uno { + class Exception; +} +namespace lang { + class XMultiServiceFactory; +} +namespace script { + class XEventAttacherManager; +} +namespace beans { + class XIntrospection; +} +} } } + + +namespace comphelper +{ + +::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager > +createEventAttacherManager( + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospection > & rIntrospection, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) + throw( ::com::sun::star::uno::Exception ); + + +::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager > +createEventAttacherManager( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) + throw( ::com::sun::star::uno::Exception ); + +} + +#endif // _COMPHELPER_EVENTATTACHERMGR_HXX_ + diff --git a/comphelper/inc/comphelper/guarding.hxx b/comphelper/inc/comphelper/guarding.hxx new file mode 100644 index 000000000000..729fdf0dc470 --- /dev/null +++ b/comphelper/inc/comphelper/guarding.hxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * $RCSfile: guarding.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_GUARDING_HXX_ +#define _COMPHELPER_GUARDING_HXX_ + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +// =================================================================================================== +// = class MutexRelease - +// =================================================================================================== + +/** opposite of OGuard :) + (a mutex is released within the constructor and acquired within the desctructor) + use only when you're sure the mutex is acquired ! +*/ +template <class MUTEX> +class ORelease +{ + MUTEX& m_rMutex; + +public: + ORelease(MUTEX& _rMutex) : m_rMutex(_rMutex) { _rMutex.release(); } + ~ORelease() { m_rMutex.acquire(); } +}; + +typedef ORelease< ::osl::Mutex > MutexRelease; + +// =================================================================================================== +// = class OCountedMutex - a Mutex which counts the acquire-/release-calls and "ensures" (with +// = assertions) that the acquire-counter isn't negative .... +// = (best used with MutexRelease to ensure that this "dangerous" class is used +// = correctly) +// =================================================================================================== + +// CAN'T USE THIS AS THERE NO SUCH THING AS IMutex ANYMORE ... +// AND OMutex DOESN'T HAVE THE VIRTUAL METHODS IMutex HAD ... +typedef ::osl::Mutex OCountedMutex; + +// =================================================================================================== +// = class OReusableGuard +// = a mutex guard which can be cleared and reattached +// =================================================================================================== +template<class T> +class OReusableGuard : public ::osl::ClearableGuard<T> +{ +public: + OReusableGuard(T& _rMutex) : ::osl::ClearableGuard<T>(_rMutex) { } + ~OReusableGuard() { } + + const OReusableGuard& operator= (const OReusableGuard& _rMaster) + { + clear(); + pT = _rMaster.pT; + if (pT) + pT->acquire(); + return *this; + } + + void attach(T& rMutex) + { + clear(); + pT = &rMutex; + pT->acquire(); + } +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_GUARDING_HXX_ + diff --git a/comphelper/inc/comphelper/numbers.hxx b/comphelper/inc/comphelper/numbers.hxx new file mode 100644 index 000000000000..12bdc159d516 --- /dev/null +++ b/comphelper/inc/comphelper/numbers.hxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * $RCSfile: numbers.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_NUMBERS_HXX_ +#define _COMPHELPER_NUMBERS_HXX_ + +#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATS_HPP_ +#include <com/sun/star/util/XNumberFormats.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_ +#include <com/sun/star/util/XNumberFormatter.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_LOCALE_HPP_ +#include <com/sun/star/lang/Locale.hpp> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starlang = ::com::sun::star::lang; + namespace starutil = ::com::sun::star::util; + + /// returns the ::com::sun::star::util::NumberFormat of the given key under the given formats + sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey); + + /// returns the ::com::sun::star::util::NumberFormat of the given key under the given formatter + sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormatter>& xFormatter, sal_Int32 nKey); + + /// returns the decimals of the given numeric number formatunder the given formats + staruno::Any getNumberFormatDecimals(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey); + + /** returns the standard format for the given type and the given _rLocale + */ + sal_Int32 getStandardFormat( + const staruno::Reference<starutil::XNumberFormatter>& xFormatter, + sal_Int16 nType, + const starlang::Locale& _rLocale); + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_NUMBERS_HXX_ + diff --git a/comphelper/inc/comphelper/oslfile2streamwrap.hxx b/comphelper/inc/comphelper/oslfile2streamwrap.hxx new file mode 100644 index 000000000000..6e116c208b2e --- /dev/null +++ b/comphelper/inc/comphelper/oslfile2streamwrap.hxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * $RCSfile: oslfile2streamwrap.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ +#define _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ + +#ifndef _OSL_MUTEX_HXX_ //autogen wg. ::osl::Mutex +#include <osl/mutex.hxx> +#endif + +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + + +namespace comphelper +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +//================================================================== +// FmUnoIOStream, +// stream zum schreiben un lesen von Daten, basieren auf File +//================================================================== +typedef ::cppu::WeakImplHelper1<stario::XInputStream> InputStreamWrapper_Base; + // needed for some compilers +class OSLInputStreamWrapper : public InputStreamWrapper_Base +{ + ::osl::Mutex m_aMutex; + ::osl::File* m_pFile; + sal_Bool m_bFileOwner : 1; + +public: + OSLInputStreamWrapper(::osl::File& _rStream); + OSLInputStreamWrapper(::osl::File* pStream, sal_Bool bOwner=sal_False); + virtual ~OSLInputStreamWrapper(); + +// UNO Anbindung + virtual void SAL_CALL acquire() throw(::com::sun::star::uno::RuntimeException) + { InputStreamWrapper_Base::acquire(); } + virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) + { InputStreamWrapper_Base::release(); } + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException) + { return InputStreamWrapper_Base::queryInterface(_rType); } + +// stario::XInputStream + virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException); + virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException); +}; + +//================================================================== +// FmUnoOutStream, +// Datensenke fuer Files +//================================================================== +typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base; + // needed for some compilers +class OSLOutputStreamWrapper : public OutputStreamWrapper_Base +{ + ::osl::File& rFile; + +public: + OSLOutputStreamWrapper(::osl::File& _rFile) :rFile(_rFile) { } + +// UNO Anbindung + virtual void SAL_CALL acquire() throw(::com::sun::star::uno::RuntimeException) + { OutputStreamWrapper_Base::acquire(); } + virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) + { OutputStreamWrapper_Base::release(); } + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException) + { return OutputStreamWrapper_Base::queryInterface(_rType); } + +// stario::XOutputStream + virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); +}; + +} // namespace comphelper + + +#endif // _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ + diff --git a/comphelper/inc/comphelper/processfactory.hxx b/comphelper/inc/comphelper/processfactory.hxx new file mode 100644 index 000000000000..71c8dd0c670f --- /dev/null +++ b/comphelper/inc/comphelper/processfactory.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * $RCSfile: processfactory.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#define _COMPHELPER_PROCESSFACTORY_HXX_ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif + +namespace com { namespace sun { namespace star { namespace lang { + class XMultiServiceFactory; +} } } } + +namespace comphelper +{ + +/** + * This function set the process service factory. + * + * @author Juergen Schmidt + */ +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 + */ +::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getProcessServiceFactory(); + +} + +#endif // _COMPHELPER_PROCESSFACTORY_HXX_ + diff --git a/comphelper/inc/comphelper/propagg.hxx b/comphelper/inc/comphelper/propagg.hxx new file mode 100644 index 000000000000..02f928e8bce7 --- /dev/null +++ b/comphelper/inc/comphelper/propagg.hxx @@ -0,0 +1,278 @@ +/************************************************************************* + * + * $RCSfile: propagg.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_AGGREGATION_HXX_ +#define _COMPHELPER_PROPERTY_AGGREGATION_HXX_ + +#ifndef _COM_SUN_STAR_UNO_XAGGREGATION_HPP_ +#include <com/sun/star/uno/XAggregation.hpp> +#endif + +#ifndef _COMPHELPER_PROPERTY_STATE_HXX_ +#include <comphelper/propstate.hxx> +#endif + +#ifndef __SGI_STL_MAP +#include <stl/map> +#endif + +//========================================================================= +//= property helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//================================================================== +//= OPropertyAccessor +//= internal helper class for OPropertyArrayAggregationHelper +//================================================================== +namespace internal +{ + struct OPropertyAccessor + { + sal_Int32 nOriginalHandle; + sal_Int32 nPos; + sal_Bool bAggregate; + + OPropertyAccessor(sal_Int32 _nOriginalHandle, sal_Int32 _nPos, sal_Bool _bAggregate) + :nOriginalHandle(_nOriginalHandle) ,nPos(_nPos) ,bAggregate(_bAggregate) { } + OPropertyAccessor() + :nOriginalHandle(-1) ,nPos(-1) ,bAggregate(sal_False) { } + + sal_Bool operator==(const OPropertyAccessor& rOb) const { return nPos == rOb.nPos; } + sal_Bool operator <(const OPropertyAccessor& rOb) const { return nPos < rOb.nPos; } + }; + + typedef std::map< sal_Int32, OPropertyAccessor, ::std::less< sal_Int32 > > PropertyAccessorMap; + typedef PropertyAccessorMap::iterator PropertyAccessorMapIterator; + typedef PropertyAccessorMap::const_iterator ConstPropertyAccessorMapIterator; +} + +//================================================================== +/** + * used as callback for a OPropertyArrayAggregationHelper + */ +class IPropertyInfoService +{ +public: + /** get the prefered handle for the given property + @param _rName the property name + @return the handle the property should be refered by, or -1 if there are no + preferences for the given property + */ + virtual sal_Int32 getPreferedPropertyId(const ::rtl::OUString& _rName) = 0; +}; + +/** + * used for implementing an cppu::IPropertyArrayHelper for classes + * aggregating property sets + */ + +#define DEFAULT_AGGREGATE_PROPERTY_ID 10000 +//------------------------------------------------------------------ +class OPropertyArrayAggregationHelper: public cppu::IPropertyArrayHelper +{ + friend class OPropertySetAggregationHelper; +protected: + + staruno::Sequence<starbeans::Property> m_aProperties; + internal::PropertyAccessorMap m_aPropertyAccessors; + +public: + /** construct the object. + @param _rProperties the properties of the object doing the aggregation. These properties + are used without any checks, so the caller has to ensure that the names and + handles are valid. + @param _rAggProperties the properties of the aggregate, usually got via an call to getProperties on the + XPropertySetInfo of the aggregate. + The names of the properties are used without any checks, so the caller has to ensure + that there are no doubles. + The handles are stored for later quick access, but the outside-handles the + aggregate properties get depend from the following two parameters. + @param _pInfoService + If not NULL, the object pointed to is used to calc handles which should be used + for refering the aggregate's properties from outside. + If one of the properties returned from the info service conflict with other handles + alread present (e.g. through _rProperties), the property is handled as if -1 was returned. + If NULL (or, for a special property, a call to getPreferedPropertyId returns -1), + the aggregate property(ies) get a new handle which they can be refered by from outside. + @param _nFirstAggregateId + if the object is about to create new handles for the aggregate properties, it uses + id's ascending from this given id. + No checks are made if the handle range determined by _nFirstAggregateId conflicts with other + handles within _rProperties. + */ + OPropertyArrayAggregationHelper(const staruno::Sequence<starbeans::Property>& _rProperties, + const staruno::Sequence<starbeans::Property>& _rAggProperties, + IPropertyInfoService* _pInfoService = NULL, + sal_Int32 _nFirstAggregateId = DEFAULT_AGGREGATE_PROPERTY_ID); + + + /// inherited from IPropertyArrayHelper + virtual sal_Bool SAL_CALL fillPropertyMembersByHandle( ::rtl::OUString* _pPropName, sal_Int16* _pAttributes, + sal_Int32 _nHandle) ; + + /// inherited from IPropertyArrayHelper + virtual staruno::Sequence<starbeans::Property> SAL_CALL getProperties(); + /// inherited from IPropertyArrayHelper + virtual starbeans::Property SAL_CALL getPropertyByName(const ::rtl::OUString& _rPropertyName) + throw(starbeans::UnknownPropertyException); + + /// inherited from IPropertyArrayHelper + virtual sal_Bool SAL_CALL hasPropertyByName(const ::rtl::OUString& _rPropertyName) ; + /// inherited from IPropertyArrayHelper + virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString & _rPropertyName); + /// inherited from IPropertyArrayHelper + virtual sal_Int32 SAL_CALL fillHandles( /*out*/sal_Int32* _pHandles, const staruno::Sequence< ::rtl::OUString >& _rPropNames ); + + /** returns information about a property of the aggregate. + @param _pPropName points to a string to recieve the property name. No name is returned if this is NULL. + @param _pOriginalHandle points to a sal_Int32 to recieve the original property hande. No original handle is returned + if this is NULL. + @param _nHandle the handle of the property as got by, for instance, fillHandles + + @return sal_True, if _nHandle marks an aggregate property, otherwise sal_False + */ + virtual sal_Bool SAL_CALL fillAggregatePropertyInfoByHandle(::rtl::OUString* _pPropName, sal_Int32* _pOriginalHandle, + sal_Int32 _nHandle) const; + +protected: + starbeans::Property* findPropertyByName(const ::rtl::OUString& _rName) const; +}; + +//================================================================== +/** + * helper class for implementing the property-set-related interfaces + * for an object doin' aggregation + * supports at least XPropertySet and XMultiPropertySet + * + */ + +class OPropertySetAggregationHelper :public OPropertyStateHelper + ,public starbeans::XPropertiesChangeListener + ,public starbeans::XVetoableChangeListener +{ +protected: + staruno::Reference<starbeans::XPropertyState> m_xAggregateState; + staruno::Reference<starbeans::XPropertySet> m_xAggregateSet; + staruno::Reference<starbeans::XMultiPropertySet> m_xAggregateMultiSet; + staruno::Reference<starbeans::XFastPropertySet> m_xAggregateFastSet; + + sal_Bool m_bListening : 1; +public: + OPropertySetAggregationHelper(cppu::OBroadcastHelper& rBHelper) + :OPropertyStateHelper(rBHelper) ,m_bListening(sal_False) { } + + virtual staruno::Any SAL_CALL queryInterface(const staruno::Type& aType) throw(staruno::RuntimeException); + +// XEventListener + virtual void SAL_CALL disposing(const starlang::EventObject& Source) throw (staruno::RuntimeException); + +// XFastPropertySet + virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const staruno::Any& aValue) throw(starbeans::UnknownPropertyException, starbeans::PropertyVetoException, starlang::IllegalArgumentException, starlang::WrappedTargetException, staruno::RuntimeException); + virtual staruno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException); + +// XPropertySet + virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString& aPropertyName, const staruno::Reference< starbeans::XPropertyChangeListener >& xListener) throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException); + virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString& PropertyName, const staruno::Reference< starbeans::XVetoableChangeListener >& aListener) throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException); + +// XPropertiesChangeListener + virtual void SAL_CALL propertiesChange(const staruno::Sequence< starbeans::PropertyChangeEvent >& evt) throw(staruno::RuntimeException); + +// XVetoableChangeListener + virtual void SAL_CALL vetoableChange(const starbeans::PropertyChangeEvent& aEvent) throw(starbeans::PropertyVetoException, staruno::RuntimeException); + +// XMultiPropertySet + virtual void SAL_CALL setPropertyValues(const staruno::Sequence< ::rtl::OUString >& PropertyNames, const staruno::Sequence< staruno::Any >& Values) throw(starbeans::PropertyVetoException, starlang::IllegalArgumentException, starlang::WrappedTargetException, staruno::RuntimeException); + virtual void SAL_CALL addPropertiesChangeListener(const staruno::Sequence< ::rtl::OUString >& aPropertyNames, const staruno::Reference< starbeans::XPropertiesChangeListener >& xListener) throw(staruno::RuntimeException); + +// XPropertyState + virtual starbeans::PropertyState SAL_CALL getPropertyState(const ::rtl::OUString& PropertyName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault(const ::rtl::OUString& PropertyName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException); + virtual staruno::Any SAL_CALL getPropertyDefault(const ::rtl::OUString& aPropertyName) throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException); + +// OPropertySetHelper + /** still waiting to be overwritten ... + you <B>must<B/> use an OPropertyArrayAggregationHelper here, as the implementation strongly relies on this. + */ + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() = 0; + +protected: + + virtual void SAL_CALL getFastPropertyValue(staruno::Any& rValue, sal_Int32 nHandle) const; + virtual void SAL_CALL disposing(); + + sal_Int32 getOriginalHandle(sal_Int32 nHandle) const; + + /// must be called before aggregation, if aggregation is used + void setAggregation(const staruno::Reference< staruno::XInterface >&) throw( starlang::IllegalArgumentException ); + void startListening(); +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_AGGREGATION_HXX_ + diff --git a/comphelper/inc/comphelper/property.hxx b/comphelper/inc/comphelper/property.hxx new file mode 100644 index 000000000000..50adc77388bd --- /dev/null +++ b/comphelper/inc/comphelper/property.hxx @@ -0,0 +1,191 @@ +/************************************************************************* + * + * $RCSfile: property.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_HXX_ +#define _COMPHELPER_PROPERTY_HXX_ + +#ifndef _CPPUHELPER_PROPTYPEHLP_HXX +#include <cppuhelper/proptypehlp.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif + +//========================================================================= +//= property helper classes +//========================================================================= + +//... namespace comphelper ....................................................... +namespace comphelper +{ +//......................................................................... + + namespace starbeans = ::com::sun::star::beans; + namespace staruno = ::com::sun::star::uno; + +/** compare two properties by name +*/ +extern int +#if defined( WNT ) + __cdecl +#endif +#if defined( ICC ) && defined( OS2 ) +_Optlink +#endif + PropertyCompare( const void* pFirst, const void* pSecond); + +//------------------------------------------------------------------ +/// remove the property with the given name from the given sequence +void RemoveProperty(staruno::Sequence<starbeans::Property>& seqProps, const ::rtl::OUString& _rPropName); + +//------------------------------------------------------------------ +/** within the given property sequence, modify attributes of a special property + @param _rProps the sequence of properties to search in + @param _sPropName the name of the property which's attributes should be modified + @param _nAddAttrib the attributes which should be added + @param _nRemoveAttrib the attributes which should be removed +*/ +void ModifyPropertyAttributes(staruno::Sequence<starbeans::Property>& _rProps, const ::rtl::OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib); + +//------------------------------------------------------------------ +/** check if the given set has the given property. +*/ +sal_Bool hasProperty(const rtl::OUString& _rName, const staruno::Reference<starbeans::XPropertySet>& _rxSet); + +//------------------------------------------------------------------ +/** copy properties between property sets, in compliance with the property + attributes of the target object +*/ +void copyProperties(const staruno::Reference<starbeans::XPropertySet>& _rxSource, + const staruno::Reference<starbeans::XPropertySet>& _rxDest); + +//================================================================== +//= property conversion helpers +//================================================================== + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue + @param _rConvertedValue the conversion result (if successfull) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) +*/ +template <class TYPE> +sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, const TYPE& _rCurrentValue) +{ + sal_Bool bModified(sal_False); + TYPE aNewValue; + ::cppu::convertPropertyValue(aNewValue, _rValueToSet); + if (aNewValue != _rCurrentValue) + { + _rConvertedValue <<= aNewValue; + _rOldValue <<= _rCurrentValue; + bModified = sal_True; + } + return bModified; +} + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for boolean properties + @param _rConvertedValue the conversion result (if successfull) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to a boolean type +*/ +inline sal_Bool tryPropertyValue(staruno::Any& /*out*/_rConvertedValue, staruno::Any& /*out*/_rOldValue, const staruno::Any& _rValueToSet, sal_Bool _bCurrentValue) +{ + sal_Bool bModified(sal_False); + sal_Bool bNewValue; + ::cppu::convertPropertyValue(bNewValue, _rValueToSet); + if (bNewValue != _bCurrentValue) + { + _rConvertedValue.setValue(&bNewValue, ::getBooleanCppuType()); + _rOldValue.setValue(&_bCurrentValue, ::getBooleanCppuType()); + bModified = sal_True; + } + return bModified; +} + +/** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue + @param _rConvertedValue the conversion result (if successfull) + @param _rOldValue the old value of the property, calculated from _rCurrentValue + @param _rValueToSet the new value which is about to be set + @param _rCurrentValue the current value of the property + @param _rExpectedType the type which the property should have (if not void) + @return sal_True, if the value could be converted and has changed + sal_False, if the value could be converted and has not changed + @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument) +*/ +sal_Bool tryPropertyValue(staruno::Any& _rConvertedValue, staruno::Any& _rOldValue, const staruno::Any& _rValueToSet, staruno::Any& _rCurrentValue, const staruno::Type& _rExpectedType); + +//......................................................................... +} +//... namespace comphelper ....................................................... + +#endif // _COMPHELPER_PROPERTY_HXX_ + diff --git a/comphelper/inc/comphelper/propertycontainer.hxx b/comphelper/inc/comphelper/propertycontainer.hxx new file mode 100644 index 000000000000..bbb47fa920b3 --- /dev/null +++ b/comphelper/inc/comphelper/propertycontainer.hxx @@ -0,0 +1,256 @@ +/************************************************************************* + * + * $RCSfile: propertycontainer.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_ +#define _COMPHELPER_PROPERTYCONTAINER_HXX_ + +#ifndef _CPPUHELPER_PROPSHLP_HXX +#include <cppuhelper/propshlp.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif +#ifndef __SGI_STL_VECTOR +#include <stl/vector> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//========================================================================== +//= OPropertyContainer +//========================================================================== +typedef ::cppu::OPropertySetHelper OPropertyContainer_Base; +/** a OPropertySetHelper implementation which is just a simple container for properties represented + by class members, usually in a derived class. + <BR> + A restriction of this class is that no value conversions are made on a setPropertyValue call. Though + the base class supports this with the convertFastPropertyValue method, the OPropertyContainer accepts only + values which already have the correct type, it's unable to convert, for instance, a long to a short. +*/ +class OPropertyContainer : public OPropertyContainer_Base +{ + typedef ::std::vector< ::com::sun::star::uno::Any > PropertyContainer; + typedef PropertyContainer::iterator PropertyContainerIterator; + typedef PropertyContainer::const_iterator ConstPropertyContainerIterator; + PropertyContainer m_aHoldProperties; + // the properties which are hold by this class' instance, not the derived one's + +public: + // (the following struct needs to be public because of the SUNPRO5 compiler. Else it does not + // acceppt the typedef below, which is using this struct). + + // infos about one single property + struct PropertyDescription + { + // the possibilities where a property holding object may be located + enum LocationType + { + ltDerivedClassRealType, // within the derived class, it's a "real" (non-Any) type + ltDerivedClassAnyType, // within the derived class, it's a <type scope="com.sun.star.uno">Any</type> + ltHoldMyself // within m_aHoldProperties + }; + // the location of an object holding a property value : + union LocationAccess + { + void* pDerivedClassMember; // a pointer to a member of an object of a derived class + sal_Int32 nOwnClassVectorIndex; // an index within m_aHoldProperties + }; + + ::rtl::OUString sName; // the name + sal_Int32 nHandle; // the handle + sal_Int32 nAttributes; // the attributes + LocationType eLocated; // where is the object containing the value located ? + LocationAccess aLocation; // access to the property value + ::com::sun::star::uno::Type + aType; // the type + + PropertyDescription() : nHandle(-1), nAttributes(0), eLocated(ltHoldMyself) + { aLocation.nOwnClassVectorIndex = -1; } + }; + +private: + // comparing two property descriptions + struct PropertyDescriptionCompareByHandle : public ::std::binary_function< PropertyDescription, PropertyDescription, sal_Bool > + { + bool operator() (const PropertyDescription& x, const PropertyDescription& y) const + { + return x.nHandle < y.nHandle; + } + }; + +private: + typedef ::std::vector< PropertyDescription > Properties; + typedef Properties::iterator PropertiesIterator; + typedef Properties::const_iterator ConstPropertiesIterator; + Properties m_aProperties; + + sal_Bool m_bAlreadyAccessed; // no addition of properties allowed anymore if this is sal_True + +protected: + OPropertyContainer(::cppu::OBroadcastHelper& _rBHelper); + + /// for scripting : the types of the interfaces supported by this class + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); + + /** register a property. The property is represented through a member of the derived class which calls + this methdod. + @param _rName the name of the property + @param _nHandle the handle of the property + @param _nAttributes the attributes of the property + @param _pPointerToMember the pointer to the member representing the property + within the derived class. + @param _rMemberType the cppu type of the property represented by the object + to which _pPointerToMember points. + */ + void registerProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + void* _pPointerToMember, const ::com::sun::star::uno::Type& _rMemberType); + + + /** register a property. The property is represented through a ::com::sun::star::uno::Any member of the + derived class which calls this methdod. + @param _rName the name of the property + @param _nHandle the handle of the property + @param _nAttributes the attributes of the property + @param _pPointerToMember the pointer to the member representing the property + within the derived class, which has to be a ::com::sun::star::uno::Any. + @param _rExpectedType the expected type of the property. NOT the type of the object to which + _pPointerToMember points (this is always an Any). + */ + void registerMayBeVoidProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + ::com::sun::star::uno::Any* _pPointerToMember, const ::com::sun::star::uno::Type& _rExpectedType); + + /** register a property. The repository will create an own object holding this property, so there is no + need to declare an extra member in your derived class + @param _rName the name of the property + @param _nHandle the handle of the property + @param _nAttributes the attributes of the property + @param _rType the type of the property + @param _pInitialValue the initial value of the property. May be null if _nAttributes includes + the ::com::sun::star::beans::PropertyAttribute::MAYBEVOID flag. + Else it must be a pointer to an object of the type described by _rType. + */ + void registerPropertyNoMember(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + const ::com::sun::star::uno::Type& _rType, void* _pInitialValue); + + +// OPropertySetHelper overridables + virtual sal_Bool SAL_CALL convertFastPropertyValue( + ::com::sun::star::uno::Any & rConvertedValue, + ::com::sun::star::uno::Any & rOldValue, + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException); + + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) + throw (::com::sun::star::uno::Exception); + + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, + sal_Int32 nHandle + ) const; + + // disambiguate a base class' member + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) = 0; + +// helper + /** appends the descriptions of all properties which were registered 'til that moment to the given sequence, + keeping the array sorted (by name) + @precond the given sequence is already sorted by name + @param _rProps initial property sequence which is to be extended + */ + void describeProperties(::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps) const; + + /** modify the attributes of an already registered property.<BR> + You may want to use this if you're a derived from OPropertyContainer indirect and want to override + some settings your base class did.<BR> + */ + void modifyAttributes(sal_Int32 _nHandle, sal_Int32 _nAddAttrib, sal_Int32 _nRemoveAttrib); + +private: + /// insertion of _rProp into m_aProperties, keeping the sort order + void implPushBackProperty(const PropertyDescription& _rProp); + + /// search the PropertyDescription for the given handle (within m_aProperties) + PropertiesIterator searchHandle(sal_Int32 _nHandle); +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTYCONTAINER_HXX_ + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * Revision 1.1 2000/09/21 08:51:34 fs + * base class for classes which are simple property containers + * + * + * Revision 1.0 21.09.00 08:16:18 fs + ************************************************************************/ + diff --git a/comphelper/inc/comphelper/propmultiplex.hxx b/comphelper/inc/comphelper/propmultiplex.hxx new file mode 100644 index 000000000000..a9aa833ee79e --- /dev/null +++ b/comphelper/inc/comphelper/propmultiplex.hxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * $RCSfile: propmultiplex.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ +#define _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ + +#ifndef _COMPHELPER_PROPERTY_STATE_HXX_ +#include <comphelper/propstate.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +//========================================================================= +//= property helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starbeans = ::com::sun::star::beans; + +//================================================================== +//= OPropertyChangeListener +//================================================================== +/// simple listener adapter for property sets +class OPropertyChangeListener +{ + friend class OPropertyChangeMultiplexer; + + OPropertyChangeMultiplexer* m_pAdapter; + ::osl::Mutex& m_rMutex; + +public: + OPropertyChangeListener(::osl::Mutex& _rMutex) + :m_rMutex(_rMutex) ,m_pAdapter(NULL) { } + virtual ~OPropertyChangeListener(); + + virtual void _propertyChanged(const starbeans::PropertyChangeEvent& evt) throw(staruno::RuntimeException) = 0; + +protected: + void setAdapter(OPropertyChangeMultiplexer* _pAdapter); +}; + +//================================================================== +//= OPropertyChangeMultiplexer +//================================================================== +/// multiplexer for property changes +class OPropertyChangeMultiplexer :public cppu::WeakImplHelper1<starbeans::XPropertyChangeListener> +{ + friend class OPropertyChangeListener; + staruno::Sequence< ::rtl::OUString > m_aProperties; + staruno::Reference<starbeans::XPropertySet> m_xSet; + OPropertyChangeListener* m_pListener; + + + virtual ~OPropertyChangeMultiplexer(); +public: + OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const staruno::Reference<starbeans::XPropertySet>& _rxSet); + +// XEventListener + virtual void SAL_CALL disposing( const starlang::EventObject& Source ) throw(staruno::RuntimeException); + +// XPropertyChangeListener + virtual void SAL_CALL propertyChange( const starbeans::PropertyChangeEvent& evt ) throw(staruno::RuntimeException); + + + void addProperty(const ::rtl::OUString& aPropertyName); + void dispose(); +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ + diff --git a/comphelper/inc/comphelper/propstate.hxx b/comphelper/inc/comphelper/propstate.hxx new file mode 100644 index 000000000000..2611c22606fd --- /dev/null +++ b/comphelper/inc/comphelper/propstate.hxx @@ -0,0 +1,127 @@ +/************************************************************************* + * + * $RCSfile: propstate.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_STATE_HXX_ +#define _COMPHELPER_PROPERTY_STATE_HXX_ + +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_ +#include <com/sun/star/beans/XPropertyState.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + + +#ifndef _CPPUHELPER_PROPSHLP_HXX +#include <cppuhelper/propshlp.hxx> +#endif +#ifndef _CPPUHELPER_PROPTYPEHLP_HXX +#include <cppuhelper/proptypehlp.hxx> +#endif + +//========================================================================= +//= property helper classes +//========================================================================= + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starlang = ::com::sun::star::lang; + namespace starbeans = ::com::sun::star::beans; + +//================================================================== +//= OPropertyStateHelper +//================================================================== +/// helper class for implementing property states +class OPropertyStateHelper :public cppu::OPropertySetHelper + ,public starbeans::XPropertyState +{ +public: + OPropertyStateHelper(cppu::OBroadcastHelper& rBHelper):OPropertySetHelper(rBHelper) { } + + virtual staruno::Any SAL_CALL queryInterface(const staruno::Type& aType) throw(staruno::RuntimeException); + +// XPropertyState + virtual starbeans::PropertyState SAL_CALL getPropertyState(const ::rtl::OUString& PropertyName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException); + virtual staruno::Sequence<starbeans::PropertyState> SAL_CALL getPropertyStates(const staruno::Sequence< ::rtl::OUString >& aPropertyName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException); + virtual void SAL_CALL setPropertyToDefault(const ::rtl::OUString& PropertyName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException); + virtual staruno::Any SAL_CALL getPropertyDefault(const ::rtl::OUString& aPropertyName) throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException); + +// access via handle + virtual starbeans::PropertyState getPropertyStateByHandle(sal_Int32 nHandle); + virtual void setPropertyToDefaultByHandle(sal_Int32 nHandle); + virtual staruno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const; + +protected: + void firePropertyChange(sal_Int32 nHandle, const staruno::Any& aNewValue, const staruno::Any& aOldValue); + + virtual staruno::Sequence<staruno::Type> SAL_CALL getTypes() throw(staruno::RuntimeException); +}; + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_PROPERTY_STATE_HXX_ + diff --git a/comphelper/inc/comphelper/querydeep.hxx b/comphelper/inc/comphelper/querydeep.hxx new file mode 100644 index 000000000000..a14f2785f163 --- /dev/null +++ b/comphelper/inc/comphelper/querydeep.hxx @@ -0,0 +1,526 @@ +/************************************************************************* + * + * $RCSfile: querydeep.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_QUERYDEEPINTERFACE_HXX +#define _COMPHELPER_QUERYDEEPINTERFACE_HXX + +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif + +/** */ //for docpp +namespace comphelper +{ + +//-------------------------------------------------------------------------------------------------------- +/** + * Inspect interfaces types whether they are related by inheritance. + *<BR> + * @return true if rType is derived from rBaseType + * @param rBaseType a <type>Type</type> of an interface. + * @param rType a <type>Type</type> of an interface. + */ +sal_Bool isDerivedFrom( + const ::com::sun::star::uno::Type & rBaseType, + const ::com::sun::star::uno::Type & rType ); + +//-------------------------------------------------------------------------------------------------------- +/** + * Inspect interface types whether they are related by inheritance. + *<BR> + * @return true if p is of a type derived from rBaseType + * @param rBaseType a <type>Type</type> of an interface. + * @param p a pointer to an interface. + */ +template <class Interface> +inline sal_Bool isDerivedFrom( + const ::com::sun::star::uno::Type& rBaseType, + Interface* /*p*/) +{ + return isDerivedFrom( + rBaseType, + ::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 comphelper + +#endif // _COMPHELPER_QUERYDEEPINTERFACE_HXX + diff --git a/comphelper/inc/comphelper/regpathhelper.hxx b/comphelper/inc/comphelper/regpathhelper.hxx new file mode 100644 index 000000000000..bf50c78cf6cd --- /dev/null +++ b/comphelper/inc/comphelper/regpathhelper.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * $RCSfile: regpathhelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_REGPATHHELPER_HXX_ +#define _COMPHELPER_REGPATHHELPER_HXX_ + +#ifndef _RTL_OUSTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +namespace comphelper +{ + +/** + * This function returns a path to the user registry file. + * Search for the user registry using the following rules: + * <dl> + * <dt> 1. (for further use) search in sversion.ini (.sversionrc) for an entry + * REGISTRY_VERSION_STRING (example: UserRegistry 5.0/505=test.rdb) in the section + * [Registry]. If found, then take this value instead of the name "user.rdb". + * <dt> 2. Search in the config directory of the user for a file "user.rdb". If + * found return the full path and name of the file. If not found, retry this + * step with a dot before ".user.rdb". + * <dt> 3. If not found a new user registry with name "user.rdb" will be created in the user + * config directory. + * </dl> + *<BR> + * @author Juergen Schmidt + */ +::rtl::OUString getPathToUserRegistry(); + +/** + * This function returns a path to the system registry file. + * The system registry will always be searched in the same directory of the + * executable. The name of the system registry is "applicat.rdb". If the system + * registry was not found, then the environment variable STAR_REGISTRY will be checked. + * If this variable was set, it must contain a full path to a valid system registry. + * Search for the user registry using the following rules: + * + *<BR> + * @author Juergen Schmidt + */ + +::rtl::OUString getPathToSystemRegistry(); + +} + +#endif + diff --git a/comphelper/inc/comphelper/seqstream.hxx b/comphelper/inc/comphelper/seqstream.hxx new file mode 100644 index 000000000000..c389ca83c2b0 --- /dev/null +++ b/comphelper/inc/comphelper/seqstream.hxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * $RCSfile: seqstream.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COMPHELPER_SEQSTREAM_HXX +#define _COMPHELPER_SEQSTREAM_HXX + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +namespace comphelper +{ + + namespace staruno = ::com::sun::star::uno; + namespace stario = ::com::sun::star::io; + + typedef staruno::Sequence<sal_Int8> ByteSequence; + +//================================================================== +// SequenceInputStream +// stream for reading data from a sequence of bytes +//================================================================== + + +class SequenceInputStream +: public ::cppu::WeakImplHelper1< stario::XInputStream > +{ + ::osl::Mutex m_aMutex; + ByteSequence m_aData; + sal_Int32 m_nPos; + +public: + SequenceInputStream(const ByteSequence& rData); + +// com::sun::star::io::XInputStream + virtual sal_Int32 SAL_CALL readBytes( 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); + +private: + inline sal_Int32 avail(); +}; + +} // namespace comphelper + +#endif //_COMPHELPER_SEQSTREAM_HXX + + diff --git a/comphelper/inc/comphelper/sequence.hxx b/comphelper/inc/comphelper/sequence.hxx new file mode 100644 index 000000000000..516c02fbb4fd --- /dev/null +++ b/comphelper/inc/comphelper/sequence.hxx @@ -0,0 +1,157 @@ +/************************************************************************* + * + * $RCSfile: sequence.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_SEQUENCE_HXX_ +#define _COMPHELPER_SEQUENCE_HXX_ + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + + //------------------------------------------------------------------------- + /** search the given string within the given sequence, return the positions where it was found. + if _bOnlyFirst is sal_True, only the first occurence will be returned. + */ + staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst = sal_False); + + //------------------------------------------------------------------------- + namespace internal + { + template <class T> + void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen) + { + for (sal_Int32 i=0; i<_nSourceLen; ++i, ++_pSource, ++_pDest) + *_pDest = *_pSource; + } + } + //------------------------------------------------------------------------- + /// concat two sequences + template <class T> + staruno::Sequence<T> concatSequences(const staruno::Sequence<T>& _rLeft, const staruno::Sequence<T>& _rRight) + { + sal_Int32 nLeft(_rLeft.getLength()), nRight(_rRight.getLength()); + const T* pLeft = _rLeft.getConstArray(); + const T* pRight = _rRight.getConstArray(); + + sal_Int32 nReturnLen(nLeft + nRight); + staruno::Sequence<T> aReturn(nReturnLen); + T* pReturn = aReturn.getArray(); + + internal::implCopySequence(pLeft, pReturn, nLeft); + internal::implCopySequence(pRight, pReturn, nRight); + + return aReturn; + } + + //------------------------------------------------------------------------- + /// concat three sequences + template <class T> + staruno::Sequence<T> concatSequences(const staruno::Sequence<T>& _rLeft, const staruno::Sequence<T>& _rMiddle, const staruno::Sequence<T>& _rRight) + { + sal_Int32 nLeft(_rLeft.getLength()), nMiddle(_rMiddle.getLength()), nRight(_rRight.getLength()); + const T* pLeft = _rLeft.getConstArray(); + const T* pMiddle = _rMiddle.getConstArray(); + const T* pRight = _rRight.getConstArray(); + + sal_Int32 nReturnLen(nLeft + nMiddle + nRight); + staruno::Sequence<T> aReturn(nReturnLen); + T* pReturn = aReturn.getArray(); + + internal::implCopySequence(pLeft, pReturn, nLeft); + internal::implCopySequence(pMiddle, pReturn, nMiddle); + internal::implCopySequence(pRight, pReturn, nRight); + + return aReturn; + } + + //------------------------------------------------------------------------- + /// remove a specified element from a sequences + template<class T> + void removeElementAt(staruno::Sequence<T>& _rSeq, sal_Int32 _nPos) + { + sal_uInt32 nLength = _rSeq.getLength(); + + OSL_ENSHURE(0 <= _nPos && _nPos < nLength, "invalid index"); + + for(int i = _nPos+1; i < nLength; ++i) + { + _rSeq[i-1] = _rSeq[i]; + } + + _rSeq.realloc(nLength-1); + } +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_SEQUENCE_HXX_ + diff --git a/comphelper/inc/comphelper/streamsection.hxx b/comphelper/inc/comphelper/streamsection.hxx new file mode 100644 index 000000000000..6aa678502dcb --- /dev/null +++ b/comphelper/inc/comphelper/streamsection.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * $RCSfile: streamsection.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_STREAMSECTION_HXX_ +#define _COMPHELPER_STREAMSECTION_HXX_ + +#ifndef _COM_SUN_STAR_IO_XMARKABLESTREAM_HPP_ +#include <com/sun/star/io/XMarkableStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XDATAINPUTSTREAM_HPP_ +#include <com/sun/star/io/XDataInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XDATAOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XDataOutputStream.hpp> +#endif + +namespace comphelper +{ + + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +/** implements handling for compatibly reading/writing data from/into an input/output stream. + data written in a block secured by this class should be readable by older versions which + use the same mechanism. + + @author Frank Schoenheit + @since 00/26/05 +*/ + +class OStreamSection +{ + staruno::Reference< stario::XMarkableStream > m_xMarkStream; + staruno::Reference< stario::XDataInputStream > m_xInStream; + staruno::Reference< stario::XDataOutputStream > m_xOutStream; + + sal_Int32 m_nBlockStart; + sal_Int32 m_nBlockLen; + +public: + /** starts reading of a "skippable" section of data within the given input stream<BR> + @param _rxInput the stream to read from. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + */ + OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput); + + /** starts writing of a "skippable" section of data into the given output stream + @param _rxOutput the stream the stream to write to. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + @param _nPresumedLength estimation for the length of the upcoming section. If greater 0, this + value will be written as section length and corrected (in the dtor) only if + needed. If you know how much bytes you are about to write, you may + want to use this param, saving some stream operations this way. + */ + OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0); + + /** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR> + If constructed for reading, any remaining bytes 'til the end of the section will be skipped. + */ + ~OStreamSection(); +}; + +} // namespace comphelper + +#endif // _COMPHELPER_STREAMSECTION_HXX_ + + diff --git a/comphelper/inc/comphelper/types.hxx b/comphelper/inc/comphelper/types.hxx new file mode 100644 index 000000000000..4124e5211bca --- /dev/null +++ b/comphelper/inc/comphelper/types.hxx @@ -0,0 +1,215 @@ +/************************************************************************* + * + * $RCSfile: types.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_TYPES_HXX_ +#define _COMPHELPER_TYPES_HXX_ + +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include <com/sun/star/uno/Any.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif + + +namespace com { namespace sun { namespace star { namespace awt { + struct FontDescriptor; +} } } } + +//......................................................................... +namespace comphelper +{ +//......................................................................... + + namespace staruno = ::com::sun::star::uno; + namespace starawt = ::com::sun::star::awt; + namespace starlang = ::com::sun::star::lang; + + typedef staruno::Reference< staruno::XInterface > InterfaceRef; + typedef staruno::Sequence< ::rtl::OUString > StringSequence; + + //------------------------------------------------------------------------- + /** compare the two given Anys + The comparison is deep, means if one of the Any's contains an Any which contains an Any ..., this is resolved <br/> + Other types recognized currently : FontDescriptor, ::com::sun::star::util::Date/Tim/DateTime, staruno::Sequence<sal_Int8> + */ + sal_Bool compare(const staruno::Any& rLeft, const staruno::Any& rRight); + + //------------------------------------------------------------------------- + /** compare two FontDescriptor's + */ + sal_Bool operator ==(const starawt::FontDescriptor& _rLeft, const starawt::FontDescriptor& _rRight); + inline sal_Bool operator !=(const starawt::FontDescriptor& _rLeft, const starawt::FontDescriptor& _rRight) + { + return !(_rLeft == _rRight); + } + + //------------------------------------------------------------------------- + /// returns sal_True if objects of the types given are "compatible" + sal_Bool isAssignableFrom(const staruno::Type& _rAssignable, const staruno::Type& _rFrom); + + //------------------------------------------------------------------------- + /** just a small shortcut ... + check if a type you have at hand at runtime is equal to another type you have at compile time + if all our compiler would accept function calls with explicit template arguments (like + isA<classFoo>(runtimeType)), we wouldn't need the second parameter. But unfortunally at + least the current solaris compiler doesn't allow this .... + So this function is nearly senseless .... + */ + template <class TYPE> + sal_Bool isA(const staruno::Type& _rType, TYPE* pDummy) + { + return _rType.equals(::getCppuType(pDummy)); + } + + //------------------------------------------------------------------------- + /** check if a type you have at hand at runtime is equal to another type you have at compile time + same comment as for the other isA .... + */ + template <class TYPE> + sal_Bool isA(const staruno::Any& _rVal, TYPE* pDummy) + { + return _rVal.getValueType().equals(::getCppuType(pDummy)); + } + + //------------------------------------------------------------------------- + /** check if a type you have at hand at runtime is equal to another type you have at compile time + */ + template <class TYPE> + sal_Bool isAReference(const staruno::Type& _rType, TYPE* pDummy) + { + return _rType.equals(::getCppuType(reinterpret_cast<staruno::Reference<TYPE>*>(NULL))); + } + + //------------------------------------------------------------------------- + /** check if a type you have at hand at runtime is equal to another type you have at compile time + */ + template <class TYPE> + sal_Bool isAReference(const staruno::Any& _rVal, TYPE* pDummy) + { + return _rVal.getValueType().equals(::getCppuType(reinterpret_cast<staruno::Reference<TYPE>*>(NULL))); + } + + //------------------------------------------------------------------------- + /** ask the given object for an XComponent interface and dispose on it + */ + template <class TYPE> + void disposeComponent(staruno::Reference<TYPE>& _rxComp) + { + staruno::Reference<starlang::XComponent> xComp(_rxComp, staruno::UNO_QUERY); + if (xComp.is()) + { + xComp->dispose(); + _rxComp = NULL; + } + } + + //------------------------------------------------------------------------- + /** get a com::sun::star::awt::FontDescriptor that is fully initialized with + the XXX_DONTKNOW enum values (which isn't the case if you instantiate it + via the default constructor) + */ + starawt::FontDescriptor getDefaultFont(); + +//========================================================================= +//= replacement of the former UsrAny.getXXX methods + + // may be used if you need the return value just as temporary, else it's may be too inefficient .... + + // no, we don't use templates here. This would lead to a lot of implicit uses of the conversion methods, + // which would be difficult to trace ... + + sal_Int32 getINT32(const staruno::Any& _rAny); + sal_Int16 getINT16(const staruno::Any& _rAny); + double getDouble(const staruno::Any& _rAny); + float getFloat(const staruno::Any& _rAny); + ::rtl::OUString getString(const staruno::Any& _rAny); + sal_Bool getBOOL(const staruno::Any& _rAny); + + sal_Int32 getEnumAsINT32(const staruno::Any& _rAny) throw(starlang::IllegalArgumentException); + +//= replacement of some former UsrAny.setXXX methods - can be used with rvalues + inline void setBOOL(staruno::Any& _rAny, sal_Bool _b) + { _rAny.setValue(&_b, ::getBooleanCppuType()); } + +//= extension of ::cppu::makeAny() + inline staruno::Any makeBoolAny(sal_Bool _b) + { return staruno::Any(&_b, ::getBooleanCppuType()); } + +//......................................................................... +} // namespace comphelper +//......................................................................... + +#endif // _COMPHELPER_TYPES_HXX_ + diff --git a/comphelper/prj/d.lst b/comphelper/prj/d.lst new file mode 100644 index 000000000000..6a739fe3b1e7 --- /dev/null +++ b/comphelper/prj/d.lst @@ -0,0 +1,10 @@ +..\%__SRC%\bin\*.dll %_DEST%\bin%_EXT%\*.dll +..\%__SRC%\lib\*.lib %_DEST%\lib%_EXT%\*.lib +..\%__SRC%\lib\*.so %_DEST%\lib%_EXT%\*.so +..\%__SRC%\lib\*.dylib %_DEST%\lib%_EXT%\*.dylib +..\%__SRC%\lib\*.sl %_DEST%\lib%_EXT%\*.sl +..\%__SRC%\bin\*.bin %_DEST%\bin%_EXT%\*.bin +..\%__SRC%\inc\*.bin %_DEST%\bin%_EXT%\*.bin + +mkdir: %_DEST%\inc%_EXT%\comphelper +..\inc\comphelper\*.hxx %_DEST%\inc%_EXT%\comphelper\*.hxx diff --git a/comphelper/source/container/container.cxx b/comphelper/source/container/container.cxx new file mode 100644 index 000000000000..97543c0c2d40 --- /dev/null +++ b/comphelper/source/container/container.cxx @@ -0,0 +1,200 @@ +/************************************************************************* + * + * $RCSfile: container.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_ +#include <com/sun/star/container/XIndexAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ +#include <com/sun/star/container/XChild.hpp> +#endif +#ifndef _COMPHELPER_CONTAINER_HXX_ +#include <comphelper/container.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//============================================================================== +IndexAccessIterator::IndexAccessIterator(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xStartingPoint) + :m_xStartingPoint(xStartingPoint) + ,m_xCurrentObject(NULL) +{ + OSL_ENSHURE(m_xStartingPoint.is(), "IndexAccessIterator::IndexAccessIterator : no starting point !"); +} + +//------------------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> IndexAccessIterator::Next() +{ + sal_Bool bCheckingStartingPoint = !m_xCurrentObject.is(); + // ist die aktuelle Node der Anfangspunkt ? + sal_Bool bAlreadyCheckedCurrent = m_xCurrentObject.is(); + // habe ich die aktuelle Node schon mal mittels ShouldHandleElement testen ? + if (!m_xCurrentObject.is()) + m_xCurrentObject = m_xStartingPoint; + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xSearchLoop( m_xCurrentObject); + sal_Bool bHasMoreToSearch = sal_True; + sal_Bool bFoundSomething = sal_False; + while (!bFoundSomething && bHasMoreToSearch) + { + // pre-order-traversierung + if (!bAlreadyCheckedCurrent && ShouldHandleElement(xSearchLoop)) + { + m_xCurrentObject = xSearchLoop; + bFoundSomething = sal_True; + } + else + { + // zuerst absteigen, wenn moeglich + ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> xContainerAccess(xSearchLoop, ::com::sun::star::uno::UNO_QUERY); + if (xContainerAccess.is() && xContainerAccess->getCount() && ShouldStepInto(xContainerAccess)) + { // zum ersten Child + ::com::sun::star::uno::Any aElement(xContainerAccess->getByIndex(0)); + xSearchLoop = *(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>*)aElement.getValue(); + bCheckingStartingPoint = sal_False; + + m_arrChildIndizies.push_back((sal_Int32)0); + } + else + { + // dann nach oben und nach rechts, wenn moeglich + while (m_arrChildIndizies.size() > 0) + { // (mein Stack ist nich leer, also kann ich noch nach oben gehen) + ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild> xChild(xSearchLoop, ::com::sun::star::uno::UNO_QUERY); + OSL_ENSHURE(xChild.is(), "IndexAccessIterator::Next : a content has no approriate interface !"); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> xParent( xChild->getParent()); + xContainerAccess = ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>(xParent, ::com::sun::star::uno::UNO_QUERY); + OSL_ENSHURE(xContainerAccess.is(), "IndexAccessIterator::Next : a content has an invalid parent !"); + + // den Index, den SearchLoop in diesem Parent hatte, von meinem 'Stack' + sal_Int32 nOldSearchChildIndex = m_arrChildIndizies[m_arrChildIndizies.size() - 1]; + m_arrChildIndizies.pop_back(); + + if (nOldSearchChildIndex < xContainerAccess->getCount() - 1) + { // auf dieser Ebene geht es noch nach rechts + ++nOldSearchChildIndex; + // also das naechste Child + ::com::sun::star::uno::Any aElement(xContainerAccess->getByIndex(nOldSearchChildIndex)); + xSearchLoop = *(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>*) aElement.getValue(); + bCheckingStartingPoint = sal_False; + // und dessen Position auf den 'Stack' + m_arrChildIndizies.push_back((sal_Int32)nOldSearchChildIndex); + + break; + } + // hierher komme ich, wenn es auf der aktuellen Ebene nicht nach rechts geht, dann mache ich eine darueber weiter + xSearchLoop = xParent; + bCheckingStartingPoint = sal_False; + } + + if ((m_arrChildIndizies.size() == 0) && !bCheckingStartingPoint) + { // das ist genau dann der Fall, wenn ich keinen rechten Nachbarn fuer irgendeinen der direkten Vorfahren des + // urspruenglichen xSearchLoop gefunden habe + bHasMoreToSearch = sal_False; + } + } + + if (bHasMoreToSearch) + { // ich habe in xSearchLoop jetzt ein Interface eines 'Knotens' meines 'Baumes', den ich noch abtesten kann + if (ShouldHandleElement(xSearchLoop)) + { + m_xCurrentObject = xSearchLoop; + bFoundSomething = sal_True; + } + else + if (bCheckingStartingPoint) + // ich bin noch am Anfang, konnte nicht absteigen, und habe an diesem Anfang nix gefunden -> nix mehr zu tun + bHasMoreToSearch = sal_False; + bAlreadyCheckedCurrent = sal_True; + } + } + } + + if (!bFoundSomething) + { + OSL_ENSHURE(m_arrChildIndizies.size() == 0, "IndexAccessIterator::Next : items left on stack ! how this ?"); + Invalidate(); + } + + return m_xCurrentObject; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * + * Revision 1.0 29.09.00 08:59:20 fs + ************************************************************************/ + diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx new file mode 100644 index 000000000000..407d53823cdf --- /dev/null +++ b/comphelper/source/container/enumhelper.cxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: enumhelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_ENUMHELPER_HXX_ +#include <comphelper/enumhelper.hxx> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//================================================================== +//= OEnumerationByName +//================================================================== +//------------------------------------------------------------------------------ +sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( ) throw(staruno::RuntimeException) +{ + sal_Bool bRet = sal_False; + if (m_xAccess.is() && m_aNames.getLength() > m_nPos) + bRet = sal_True; + else if (m_xAccess.is()) + m_xAccess = NULL; + + return bRet; +} + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OEnumerationByName::nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException) +{ + staruno::Any aRes; + if (m_xAccess.is() && m_nPos < m_aNames.getLength()) + aRes = m_xAccess->getByName(m_aNames.getConstArray()[m_nPos++]); + if (m_xAccess.is() && m_nPos >= m_aNames.getLength()) + m_xAccess = NULL; + + if (!aRes.hasValue()) // es gibt kein Element mehr + throw starcontainer::NoSuchElementException(); + + return aRes; +} + +//================================================================== +//= OEnumerationByIndex +//================================================================== +//------------------------------------------------------------------------------ +sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( ) throw(staruno::RuntimeException) +{ + sal_Bool bRet = sal_False; + if (m_xAccess.is() && m_xAccess->getCount() > m_nPos) + bRet = sal_True; + else if (m_xAccess.is()) + m_xAccess = NULL; + + return bRet; +} + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OEnumerationByIndex::nextElement( ) + throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException) +{ + staruno::Any aRes; + if (m_xAccess.is()) + { + aRes = m_xAccess->getByIndex(m_nPos++); + if (m_nPos >= m_xAccess->getCount()) + m_xAccess = NULL; + } + + if (!aRes.hasValue()) // es gibt kein Element mehr + throw starcontainer::NoSuchElementException(); + return aRes; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * + * Revision 1.0 29.09.00 08:47:37 fs + ************************************************************************/ + diff --git a/comphelper/source/container/makefile.mk b/comphelper/source/container/makefile.mk new file mode 100644 index 000000000000..fa119434db7c --- /dev/null +++ b/comphelper/source/container/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=comphelper +TARGET=container + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/enumhelper.obj \ + $(SLO)$/container.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx new file mode 100644 index 000000000000..3889f9ebac4a --- /dev/null +++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx @@ -0,0 +1,1134 @@ +/************************************************************************* + * + * $RCSfile: eventattachermgr.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <deque> + +#if defined( OS2 ) || defined( UNX ) || defined( MAC ) +#include <wchar.h> +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _VOS_MACROS_HXX_ +#include <vos/macros.hxx> +#endif + +#ifndef _COMPHELPER_EVENTATTACHERMGR_HXX_ +#include <comphelper/eventattachermgr.hxx> +#endif + +#ifndef _COM_SUN_STAR_BEANS_XINTROSPECTION_HPP_ +#include <com/sun/star/beans/XIntrospection.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XOBJECTINPUTSTREAM_HPP_ +#include <com/sun/star/io/XObjectInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XPERSISTOBJECT_HPP_ +#include <com/sun/star/io/XPersistObject.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XOBJECTOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XObjectOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XMARKABLESTREAM_HPP_ +#include <com/sun/star/io/XMarkableStream.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_REFLECTION_XIDLCLASS_HPP_ +#include <com/sun/star/reflection/XIdlClass.hpp> +#endif +#ifndef _COM_SUN_STAR_REFLECTION_XIDLREFLECTION_HPP_ +#include <com/sun/star/reflection/XIdlReflection.hpp> +#endif +#ifndef _COM_SUN_STAR_REFLECTION_XIDLMETHOD_HPP_ +#include <com/sun/star/reflection/XIdlMethod.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_ +#include <com/sun/star/script/XTypeConverter.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XENGINELISTENER_HPP_ +#include <com/sun/star/script/XEngineListener.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XEVENTATTACHER_HPP_ +#include <com/sun/star/script/XEventAttacher.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XEVENTATTACHERMANAGER_HPP_ +#include <com/sun/star/script/XEventAttacherManager.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XSCRIPTLISTENER_HPP_ +#include <com/sun/star/script/XScriptListener.hpp> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include <cppuhelper/implbase2.hxx> +#endif + +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::script; +using namespace com::sun::star::reflection; +using namespace cppu; +using namespace osl; +using namespace rtl; + +namespace comphelper +{ + +//----------------------------------------------------------------------------- +struct AttachedObject_Impl +{ + Reference< XInterface > xTarget; + Sequence< Reference< XEventListener > > aAttachedListenerSeq; + Any aHelper; + + bool operator<( const AttachedObject_Impl & ) const; + bool operator==( const AttachedObject_Impl & ) const; +}; + +struct AttacherIndex_Impl +{ +#ifdef DEQUE_OK + NAMESPACE_STD( deque )< ScriptEventDescriptor > aEventList; +#else + Sequence< ScriptEventDescriptor > aEventList; +#endif + NAMESPACE_STD(deque)< AttachedObject_Impl > aObjList; + + bool operator<( const AttacherIndex_Impl & ) const; + bool operator==( const AttacherIndex_Impl & ) const; +}; + +#if 0 +bool AttachedObject_Impl::operator<( const AttachedObject_Impl & r ) const +{ + VOS_ENSHURE( FALSE, "not implemented" ); + return FALSE; + return this < &r; +} + +bool AttachedObject_Impl::operator==( const AttachedObject_Impl & r ) const +{ + VOS_ENSHURE( FALSE, "not implemented" ); + return this == &r; +} + +bool AttacherIndex_Impl::operator<( const AttacherIndex_Impl & r ) const +{ + VOS_ENSHURE( FALSE, "not implemented" ); + return this < &r; +} +bool AttacherIndex_Impl::operator==( const AttacherIndex_Impl & r ) const +{ + VOS_ENSHURE( FALSE, "not implemented" ); + return this == &r; +} +#endif + +//----------------------------------------------------------------------------- +class ImplEventAttacherManager + : public WeakImplHelper2< XEventAttacherManager, XPersistObject > +{ + friend class AttacherAllListener_Impl; + NAMESPACE_STD(deque)< AttacherIndex_Impl > aIndex; + Mutex aLock; + // Container fuer die ScriptListener + OInterfaceContainerHelper aScriptListeners; + // EventAttacher-Instanz + Reference< XEventAttacher > xAttacher; + Reference< XMultiServiceFactory > mxSMgr; + Reference< XIdlReflection > mxCoreReflection; + Reference< XIntrospection > mxIntrospection; + Reference< XTypeConverter > xConverter; + sal_Int16 nVersion; +public: + ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection, + const Reference< XMultiServiceFactory > rSMgr ); + ~ImplEventAttacherManager(); + + // Methoden von XEventAttacherManager + virtual void SAL_CALL registerScriptEvent(sal_Int32 Index, const ScriptEventDescriptor& ScriptEvent) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL registerScriptEvents(sal_Int32 Index, const Sequence< ScriptEventDescriptor >& ScriptEvents) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL revokeScriptEvent(sal_Int32 Index, const OUString& ListenerType, const OUString& EventMethod, const OUString& removeListenerParam) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL revokeScriptEvents(sal_Int32 Index) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL insertEntry(sal_Int32 Index) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL removeEntry(sal_Int32 Index) + throw( IllegalArgumentException, RuntimeException ); + virtual Sequence< ScriptEventDescriptor > SAL_CALL getScriptEvents(sal_Int32 Index) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL attach(sal_Int32 Index, const Reference< XInterface >& Object, const Any& Helper) + throw( IllegalArgumentException, ServiceNotRegisteredException, RuntimeException ); + virtual void SAL_CALL detach(sal_Int32 nIndex, const Reference< XInterface >& xObject) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL addScriptListener(const Reference< XScriptListener >& aListener) + throw( IllegalArgumentException, RuntimeException ); + virtual void SAL_CALL removeScriptListener(const Reference< XScriptListener >& Listener) + throw( IllegalArgumentException, RuntimeException ); + + // Methoden von XPersistObject + virtual OUString SAL_CALL getServiceName(void) throw( RuntimeException ); + virtual void SAL_CALL write(const Reference< XObjectOutputStream >& OutStream) throw( IOException, RuntimeException ); + virtual void SAL_CALL read(const Reference< XObjectInputStream >& InStream) throw( IOException, RuntimeException ); + +private: + Reference< XIdlReflection > getReflection() throw( Exception ); +}; + +//======================================================================== +//======================================================================== +//======================================================================== + +// Implementation eines EventAttacher-bezogenen AllListeners, der +// nur einzelne Events an einen allgemeinen AllListener weiterleitet +class AttacherAllListener_Impl : public WeakImplHelper1< XAllListener > +{ + ImplEventAttacherManager* mpManager; + Reference< XEventAttacherManager > xManager; + OUString aScriptType; + OUString aScriptCode; + sal_Int16 nVersion; + + void convertToEventReturn( Any & rRet, const Type & rRetType ) + throw( CannotConvertException ); +public: + AttacherAllListener_Impl( ImplEventAttacherManager* pManager_, const OUString &rScriptType_, + const OUString & rScriptCode_ ); + + // Methoden von XAllListener + virtual void SAL_CALL firing(const AllEventObject& Event) throw( RuntimeException ); + virtual Any SAL_CALL approveFiring(const AllEventObject& Event) throw( InvocationTargetException, RuntimeException ); + + // Methoden von XEventListener + virtual void SAL_CALL disposing(const EventObject& Source) throw( RuntimeException ); +}; + +//======================================================================== +AttacherAllListener_Impl::AttacherAllListener_Impl +( + ImplEventAttacherManager* pManager_, + const OUString & rScriptType_, + const OUString & rScriptCode_ +) + : mpManager( pManager_ ) + , xManager( pManager_ ) + , aScriptType( rScriptType_ ) + , aScriptCode( rScriptCode_ ) + , nVersion( 2 ) +{ +} + + +//======================================================================== +// Methoden von XAllListener +void SAL_CALL AttacherAllListener_Impl::firing(const AllEventObject& Event) + throw( RuntimeException ) +{ + ScriptEvent aScriptEvent; + aScriptEvent.Source = (OWeakObject *)mpManager; // get correct XInterface + aScriptEvent.ListenerType = Event.ListenerType; + aScriptEvent.MethodName = Event.MethodName; + aScriptEvent.Arguments = Event.Arguments; + aScriptEvent.Helper = Event.Helper; + aScriptEvent.ScriptType = aScriptType; + aScriptEvent.ScriptCode = aScriptCode; + + // ueber alle Listener iterieren und Events senden + OInterfaceIteratorHelper aIt( mpManager->aScriptListeners ); + while( aIt.hasMoreElements() ) + ((XScriptListener *)aIt.next())->firing( aScriptEvent ); +} + +//======================================================================== +// Convert to the standard event return +void AttacherAllListener_Impl::convertToEventReturn( Any & rRet, const Type & rRetType ) + throw( CannotConvertException ) +{ + // no return value? Set to the specified values + if( rRet.getValueType().getTypeClass() == TypeClass_VOID ) + { + switch( rRetType.getTypeClass() ) + { + case TypeClass_INTERFACE: + { + rRet <<= Reference< XInterface >(); + } + break; + + case TypeClass_BOOLEAN: + rRet <<= sal_True; + break; + + case TypeClass_STRING: + rRet <<= OUString(); + break; + + case TypeClass_FLOAT: rRet <<= float(0); break; + case TypeClass_DOUBLE: rRet <<= double(0.0); break; + case TypeClass_BYTE: rRet <<= sal_uInt8(0); break; + case TypeClass_SHORT: rRet <<= sal_Int16( 0 ); break; + case TypeClass_LONG: rRet <<= sal_Int32( 0 ); break; + case TypeClass_UNSIGNED_SHORT: rRet <<= sal_uInt16( 0 ); break; + case TypeClass_UNSIGNED_LONG: rRet <<= sal_uInt32( 0 ); break; + break; + } + } + else if( !rRet.getValueType().equals( rRetType ) ) + { + if( mpManager->xConverter.is() ) + rRet = mpManager->xConverter->convertTo( rRet, rRetType ); + else + throw CannotConvertException(); + } +} + +//======================================================================== +// Methoden von XAllListener +Any SAL_CALL AttacherAllListener_Impl::approveFiring( const AllEventObject& Event ) + throw( InvocationTargetException, RuntimeException ) +{ + ScriptEvent aScriptEvent; + aScriptEvent.Source = (OWeakObject *)mpManager; // get correct XInterface + aScriptEvent.ListenerType = Event.ListenerType; + aScriptEvent.MethodName = Event.MethodName; + aScriptEvent.Arguments = Event.Arguments; + aScriptEvent.Helper = Event.Helper; + aScriptEvent.ScriptType = aScriptType; + aScriptEvent.ScriptCode = aScriptCode; + + Any aRet; + // ueber alle Listener iterieren und Events senden + OInterfaceIteratorHelper aIt( mpManager->aScriptListeners ); + while( aIt.hasMoreElements() ) + { + aRet = ((XScriptListener *)aIt.next())->approveFiring( aScriptEvent ); + try + { + Reference< XIdlClass > xListenerType = mpManager->getReflection()-> + forName( Event.ListenerType.getTypeName() ); + Reference< XIdlMethod > xMeth = xListenerType->getMethod( Event.MethodName ); + if( xMeth.is() ) + { + Reference< XIdlClass > xRetType = xMeth->getReturnType(); + Type aRetType(xRetType->getTypeClass(), xRetType->getName()); + convertToEventReturn( aRet, aRetType ); + } + + switch( aRet.getValueType().getTypeClass() ) + { + case TypeClass_INTERFACE: + { + // Interface not null, return + Reference< XInterface > x; + aRet >>= x; + if( x.is() ) + return aRet; + } + break; + + case TypeClass_BOOLEAN: + // FALSE -> Return + if( !(*(sal_Bool*)aRet.getValue()) ) + return aRet; + break; + + case TypeClass_STRING: + // none empty string -> return + if( ((OUString*)aRet.getValue())->getLength() > 0 ) + return aRet; + break; + + // none zero number -> return + case TypeClass_FLOAT: if( *((float*)aRet.getValue()) ) return aRet; break; + case TypeClass_DOUBLE: if( *((double*)aRet.getValue()) ) return aRet; break; + case TypeClass_BYTE: if( *((sal_uInt8*)aRet.getValue()) ) return aRet; break; + case TypeClass_SHORT: if( *((sal_Int16*)aRet.getValue()) ) return aRet; break; + case TypeClass_LONG: if( *((sal_Int32*)aRet.getValue()) ) return aRet; break; + case TypeClass_UNSIGNED_SHORT: if( *((sal_uInt16*)aRet.getValue()) ) return aRet; break; + case TypeClass_UNSIGNED_LONG: if( *((sal_uInt32*)aRet.getValue()) ) return aRet; break; + } + } + catch( CannotConvertException& ) + { + // silent ignore conversions errors from a script call + Reference< XIdlClass > xListenerType = mpManager->getReflection()-> + forName( Event.ListenerType.getTypeName() ); + Reference< XIdlMethod > xMeth = xListenerType->getMethod( Event.MethodName ); + if( xMeth.is() ) + { + Reference< XIdlClass > xRetType = xMeth->getReturnType(); + Type aRetType(xRetType->getTypeClass(), xRetType->getName()); + aRet.clear(); + convertToEventReturn( aRet, aRetType ); + } + } + } + return aRet; +} + +//======================================================================== +// Methoden von XEventListener +void SAL_CALL AttacherAllListener_Impl::disposing(const EventObject& ) + throw( RuntimeException ) +{ + // It is up to the container to release the object +} + + +//======================================================================== +//======================================================================== +//======================================================================== + +// Create-Methode fuer EventAttacherManager +Reference< XEventAttacherManager > createEventAttacherManager( const Reference< XIntrospection > & rIntrospection, + const Reference< XMultiServiceFactory > & rSMgr ) + throw( Exception ) +{ + return new ImplEventAttacherManager( rIntrospection, rSMgr ); +} + +// Create-Methode fuer EventAttacherManager +Reference< XEventAttacherManager > createEventAttacherManager( const Reference< XMultiServiceFactory > & rSMgr ) + throw( Exception ) +{ + if ( rSMgr.is() ) + { + Reference< XInterface > xIFace( rSMgr->createInstance( OUString::createFromAscii("com.sun.star.beans.Introspection") ) ); + if ( xIFace.is() ) + { + Reference< XIntrospection > xIntrospection( xIFace, UNO_QUERY); + return new ImplEventAttacherManager( xIntrospection, rSMgr ); + } + } + + return Reference< XEventAttacherManager >(); +} + +//----------------------------------------------------------------------------- +ImplEventAttacherManager::ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection, + const Reference< XMultiServiceFactory > rSMgr ) + : mxIntrospection( rIntrospection ) + , mxSMgr( rSMgr ) + , aScriptListeners( aLock ) +{ + if ( rSMgr.is() ) + { + Reference< XInterface > xIFace( rSMgr->createInstance( OUString::createFromAscii("com.sun.star.script.EventAttacher") ) ); + if ( xIFace.is() ) + { + xAttacher = Reference< XEventAttacher >::query( xIFace ); + } + xIFace = rSMgr->createInstance( OUString::createFromAscii("com.sun.star.script.Converter") ); + if ( xIFace.is() ) + { + xConverter = Reference< XTypeConverter >::query( xIFace ); + } + } + + Reference< XInitialization > xInit( xAttacher, UNO_QUERY ); + if( xInit.is() ) + { + Sequence< Any > Arguments( 1 ); + Arguments[0] <<= rIntrospection; + xInit->initialize( Arguments ); + } +} + +//----------------------------------------------------------------------------- +ImplEventAttacherManager::~ImplEventAttacherManager() +{ +} + +Reference< XIdlReflection > ImplEventAttacherManager::getReflection() throw( Exception ) +{ + Guard< Mutex > aGuard( aLock ); + // Haben wir den Service schon? Sonst anlegen + if( !mxCoreReflection.is() ) + { + Reference< XInterface > xIFace( mxSMgr->createInstance( OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ) ); + mxCoreReflection = Reference< XIdlReflection >( xIFace, UNO_QUERY); + } + return mxCoreReflection; +} + + +//----------------------------------------------------------------------------- +void detachAll_Impl +( + ImplEventAttacherManager * pMgr, + sal_Int32 nIdx, + NAMESPACE_STD(deque)< AttachedObject_Impl > & rList +) +{ + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjIt = rList.begin(); + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjEnd = rList.end(); + while( aObjIt != aObjEnd ) + { + pMgr->detach( nIdx, (*aObjIt).xTarget ); + aObjIt++; + } +} + +//----------------------------------------------------------------------------- +void attachAll_Impl +( + ImplEventAttacherManager * pMgr, + sal_Int32 nIdx, + NAMESPACE_STD(deque)< AttachedObject_Impl > & rList +) +{ + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjIt = rList.begin(); + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjEnd = rList.end(); + while( aObjIt != aObjEnd ) + { + pMgr->attach( nIdx, (*aObjIt).xTarget, (*aObjIt).aHelper ); + aObjIt++; + } +} + +//----------------------------------------------------------------------------- +//*** Methoden von XEventAttacherManager *** +void SAL_CALL ImplEventAttacherManager::registerScriptEvent +( + sal_Int32 nIndex, + const ScriptEventDescriptor& ScriptEvent +) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + Guard< Mutex > aGuard( aLock ); + // Index pruefen und Array anpassen + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + for( sal_Int32 i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)< AttachedObject_Impl > aList = (*aIt).aObjList; + + ScriptEventDescriptor aEvt = ScriptEvent; + const sal_Unicode* pLastDot = aEvt.ListenerType.getStr(); + pLastDot += rtl_ustr_lastIndexOfChar( pLastDot, '.' ); + if( pLastDot ) + aEvt.ListenerType = pLastDot +1; +#ifdef DEQUE_OK + (*aIt).aEventList.push_back( aEvt ); +#else + (*aIt).aEventList.realloc( (*aIt).aEventList.getLength() +1 ); + (*aIt).aEventList.getArray()[(*aIt).aEventList.getLength() -1] = aEvt; +#endif + + // register new new Event + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjIt = (*aIt).aObjList.begin(); + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjEnd = (*aIt).aObjList.end(); + while( aObjIt != aObjEnd ) + { + // resize + sal_Int32 nPos = (*aObjIt).aAttachedListenerSeq.getLength(); + (*aObjIt).aAttachedListenerSeq.realloc( nPos + 1 ); + Reference< XEventListener > * pArray = (*aObjIt).aAttachedListenerSeq.getArray(); + + Reference< XAllListener > xAll = + new AttacherAllListener_Impl( this, ScriptEvent.ScriptType, ScriptEvent.ScriptCode ); + try + { + pArray[nPos] = xAttacher->attachSingleEventListener( (*aObjIt).xTarget, xAll, + (*aObjIt).aHelper, ScriptEvent.ListenerType, + ScriptEvent.AddListenerParam, ScriptEvent.EventMethod ); + } + catch( ... ) + { + } + + aObjIt++; + } +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::registerScriptEvents +( + sal_Int32 nIndex, + const Sequence< ScriptEventDescriptor >& ScriptEvents +) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + Guard< Mutex > aGuard( aLock ); + + // Index pruefen und Array anpassen + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + sal_Int32 i; + for( i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)< AttachedObject_Impl > aList = (*aIt).aObjList; + detachAll_Impl( this, nIndex, aList ); + + const ScriptEventDescriptor* pArray = ScriptEvents.getConstArray(); + sal_Int32 nLen = ScriptEvents.getLength(); + for( i = 0 ; i < nLen ; i++ ) + registerScriptEvent( nIndex, pArray[ i ] ); + + attachAll_Impl( this, nIndex, aList ); +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::revokeScriptEvent +( + sal_Int32 nIndex, + const OUString& ListenerType, + const OUString& EventMethod, + const OUString& ToRemoveListenerParam +) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + sal_Int32 i; + for( i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)< AttachedObject_Impl > aList = (*aIt).aObjList; + detachAll_Impl( this, nIndex, aList ); + + OUString aLstType = ListenerType; + const sal_Unicode * pLastDot = aLstType.getStr(); + pLastDot += rtl_ustr_lastIndexOfChar( pLastDot, '.' ); + if( pLastDot ) + aLstType = pLastDot +1; + +#ifdef DEQUE_OK + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtIt = (*aIt).aEventList.begin(); + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtEnd = (*aIt).aEventList.end(); + while( aEvtIt != aEvtEnd ) + { + if( aLstType == (*aEvtIt).ListenerType + && EventMethod == (*aEvtIt).EventMethod + && ToRemoveListenerParam == (*aEvtIt).AddListenerParam ) + { + (*aIt).aEventList.erase( aEvtIt ); + break; + } + + aEvtIt++; + } +#else + sal_Int32 nLen = (*aIt).aEventList.getLength(); + ScriptEventDescriptor * pEL = (*aIt).aEventList.getArray(); + for( i = 0; i < nLen; i++ ) + { + if( aLstType == pEL[i].ListenerType + && EventMethod == pEL[i].EventMethod + && ToRemoveListenerParam == pEL[i].AddListenerParam ) + { + Sequence< ScriptEventDescriptor > tmpSequence( (*aIt).aEventList ); + sal_Int32 index = 0; + for ( sal_Int32 j=0; j < nLen; j++) + { + if ( j != i ) + { + (*aIt).aEventList[j] = tmpSequence[index++]; + } + } + break; + } + } +#endif + attachAll_Impl( this, nIndex, aList ); +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::revokeScriptEvents(sal_Int32 nIndex ) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + for( sal_Int32 i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)< AttachedObject_Impl > aList = (*aIt).aObjList; + detachAll_Impl( this, nIndex, aList ); +#ifdef DEQUE_OK + (*aIt).aEventList = NAMESPACE_STD( deque )< ScriptEventDescriptor >(); +#else + (*aIt).aEventList.realloc( 0 ); +#endif + attachAll_Impl( this, nIndex, aList ); +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::insertEntry(sal_Int32 nIndex) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + while( nIndex-- ) + aIt++; + + AttacherIndex_Impl aTmp; + aIndex.insert( aIt, aTmp ); +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::removeEntry(sal_Int32 nIndex) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + for( sal_Int32 i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)< AttachedObject_Impl > aList = (*aIt).aObjList; + detachAll_Impl( this, nIndex, aList ); + aIndex.erase( aIt ); +} + +//----------------------------------------------------------------------------- +Sequence< ScriptEventDescriptor > SAL_CALL ImplEventAttacherManager::getScriptEvents(sal_Int32 nIndex) + throw( IllegalArgumentException, RuntimeException ) +{ + if( nIndex < 0 ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + for( sal_Int32 i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + +#ifdef DEQUE_OK + Sequence< ScriptEventDescriptor > aSeq( (*aIt).aEventList.size() ); + ScriptEventDescriptor * pArray = aSeq.getArray(); + + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtIt = (*aIt).aEventList.begin(); + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtEnd = (*aIt).aEventList.end(); + i = 0; + while( aEvtIt != aEvtEnd ) + { + pArray[i++] = *aEvtIt; + aEvtIt++; + } + return aSeq; +#else + return (*aIt).aEventList; +#endif +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::attach(sal_Int32 nIndex, const Reference< XInterface >& xObject, const Any & Helper) + throw( IllegalArgumentException, ServiceNotRegisteredException, RuntimeException ) +{ + //return; + if( nIndex < 0 || !xObject.is() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + sal_Int32 i; + for( i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + { + // alte Dateien lesen + if( nVersion == 1 ) + { + insertEntry( nIndex ); + attach( nIndex, xObject, Helper ); + return; + } + else + throw IllegalArgumentException(); + } + + AttachedObject_Impl aTmp; + aTmp.xTarget = xObject; + aTmp.aHelper = Helper; + (*aIt).aObjList.push_back( aTmp ); + + //NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjIt = (*aIt).aObjList.back(); + AttachedObject_Impl & rCurObj = (*aIt).aObjList.back(); +#ifdef DEQUE_OK + rCurObj.aAttachedListenerSeq = Sequence< Reference< XEventListener > >( (*aIt).aEventList.size() ); +#else + rCurObj.aAttachedListenerSeq = Sequence< Reference< XEventListener > >( (*aIt).aEventList.getLength() ); +#endif + Reference< XEventListener > * pArray = rCurObj.aAttachedListenerSeq.getArray(); + +#ifdef DEQUE_OK + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtIt = (*aIt).aEventList.begin(); + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtEnd = (*aIt).aEventList.end(); + i = 0; + while( aEvtIt != aEvtEnd ) + { + Reference< XAllListener > xAll = + new AttacherAllListener_Impl( this, (*aEvtIt).ScriptType, (*aEvtIt).ScriptCode ); + Reference< XEventListener > xAdapter; + try + { + xAdapter = xAttacher->attachSingleEventListener( rCurObj.xTarget, xAll, + rCurObj.aHelper, (*aEvtIt).ScriptType, + (*aEvtIt).AddListenerParam, (*aEvtIt).EventMethod ); + } + catch( ... ) + { + } + + pArray[i++] = xAdapter; + aEvtIt++; + } +#else + sal_Int32 nLen = (*aIt).aEventList.getLength(); + ScriptEventDescriptor * pEL = (*aIt).aEventList.getArray(); + for( i = 0; i < nLen; i++ ) + { + Reference< XAllListener > xAll = + new AttacherAllListener_Impl( this, pEL[i].ScriptType, pEL[i].ScriptCode ); + Reference< XEventListener > xAdapter; + try + { + xAdapter = xAttacher->attachSingleEventListener( rCurObj.xTarget, xAll, + rCurObj.aHelper, pEL[i].ListenerType, + pEL[i].AddListenerParam, pEL[i].EventMethod ); + } + catch( ... ) + { + } + + pArray[i] = xAdapter; + } +#endif +} + +//----------------------------------------------------------------------------- +void SAL_CALL ImplEventAttacherManager::detach(sal_Int32 nIndex, const Reference< XInterface >& xObject) + throw( IllegalArgumentException, RuntimeException ) +{ + //return; + if( nIndex < 0 || !xObject.is() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + for( sal_Int32 i = 0; i < nIndex; i++ ) + aIt++; + + if( aIt == aIndex.end() ) + throw IllegalArgumentException(); + + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjIt = (*aIt).aObjList.begin(); + NAMESPACE_STD(deque)< AttachedObject_Impl >::iterator aObjEnd = (*aIt).aObjList.end(); + while( aObjIt != aObjEnd ) + { + if( (*aObjIt).xTarget == xObject ) + { + Reference< XEventListener > * pArray = (*aObjIt).aAttachedListenerSeq.getArray(); +#ifdef DEQUE_OK + + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtIt = (*aIt).aEventList.begin(); + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtEnd = (*aIt).aEventList.end(); + i = 0; + while( aEvtIt != aEvtEnd ) + { + if( pArray[i].is() ) + { + try + { + xAttacher->removeListener( (*aObjIt).xTarget, (*aEvtIt).ListenerType, + (*aEvtIt).AddListenerParam, pArray[i] ); + } + catch( ... ) + { + } + } + i++; + aEvtIt++; + } +#else + sal_Int32 nLen = (*aIt).aEventList.getLength(); + ScriptEventDescriptor * pEL = (*aIt).aEventList.getArray(); + for( sal_Int32 i = 0; i < nLen; i++ ) + { + if( pArray[i].is() ) + { + try + { + xAttacher->removeListener( (*aObjIt).xTarget, pEL[i].ListenerType, + pEL[i].AddListenerParam, pArray[i] ); + } + catch( ... ) + { + } + } + } +#endif + (*aIt).aObjList.erase( aObjIt ); + break; + } + aObjIt++; + } +} + +void SAL_CALL ImplEventAttacherManager::addScriptListener(const Reference< XScriptListener >& aListener) + throw( IllegalArgumentException, RuntimeException ) +{ + aScriptListeners.addInterface( aListener ); +} + +void SAL_CALL ImplEventAttacherManager::removeScriptListener(const Reference< XScriptListener >& aListener) + throw( IllegalArgumentException, RuntimeException ) +{ + aScriptListeners.removeInterface( aListener ); +} + + +// Methoden von XPersistObject +OUString SAL_CALL ImplEventAttacherManager::getServiceName(void) + throw( RuntimeException ) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.script.EventAttacherManager") ); +} + +void SAL_CALL ImplEventAttacherManager::write(const Reference< XObjectOutputStream >& OutStream) + throw( IOException, RuntimeException ) +{ + // Ohne XMarkableStream laeuft nichts + Reference< XMarkableStream > xMarkStream( OutStream, UNO_QUERY ); + if( !xMarkStream.is() ) + return; + + // Version schreiben + OutStream->writeShort( 2 ); + + // Position fuer Laenge merken + sal_Int32 nObjLenMark = xMarkStream->createMark(); + OutStream->writeLong( 0L ); + + OutStream->writeLong( aIndex.size() ); + + // Sequences schreiben + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aIt = aIndex.begin(); + NAMESPACE_STD(deque)<AttacherIndex_Impl>::iterator aEnd = aIndex.end(); + while( aIt != aEnd ) + { +#ifdef DEQUE_OK + // Laenge der Sequence und alle Descriptoren schreiben + OutStream->writeLong( (*aIt).aEventList.size() ); + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtIt = (*aIt).aEventList.begin(); + NAMESPACE_STD(deque)< ScriptEventDescriptor >::iterator aEvtEnd = (*aIt).aEventList.end(); + while( aEvtIt != aEvtEnd ) + { + const ScriptEventDescriptor& rDesc = (*aEvtIt); + OutStream->writeUTF( rDesc.ListenerType ); + OutStream->writeUTF( rDesc.EventMethod ); + OutStream->writeUTF( rDesc.AddListenerParam ); + OutStream->writeUTF( rDesc.ScriptType ); + OutStream->writeUTF( rDesc.ScriptCode ); + + aEvtIt++; + } +#else + sal_Int32 nLen = (*aIt).aEventList.getLength(); + // Laenge der Sequence und alle Descriptoren schreiben + OutStream->writeLong( nLen ); + ScriptEventDescriptor * pEL = (*aIt).aEventList.getArray(); + for( sal_Int32 i = 0; i < nLen; i++ ) + { + const ScriptEventDescriptor& rDesc = pEL[i]; + OutStream->writeUTF( rDesc.ListenerType ); + OutStream->writeUTF( rDesc.EventMethod ); + OutStream->writeUTF( rDesc.AddListenerParam ); + OutStream->writeUTF( rDesc.ScriptType ); + OutStream->writeUTF( rDesc.ScriptCode ); + } +#endif + aIt++; + } + + // Die jetzt bekannte Laenge eintragen + sal_Int32 nObjLen = xMarkStream->offsetToMark( nObjLenMark ) -4; + xMarkStream->jumpToMark( nObjLenMark ); + OutStream->writeLong( nObjLen ); + xMarkStream->jumpToFurthest(); + xMarkStream->deleteMark( nObjLenMark ); +} + +void SAL_CALL ImplEventAttacherManager::read(const Reference< XObjectInputStream >& InStream) + throw( IOException, RuntimeException ) +{ + // Ohne XMarkableStream laeuft nichts + Reference< XMarkableStream > xMarkStream( InStream, UNO_QUERY ); + if( !xMarkStream.is() ) + return; + + // Version lesen + nVersion = InStream->readShort(); + + // Zunaechst kommen die Daten gemaess Version 1, + // muss auch bei hoeheren Versionen beibehalten werden + sal_Int32 nLen = InStream->readLong(); + + // Position fuer Vergleichszwecke + sal_Int32 nObjLenMark = xMarkStream->createMark(); + + // Anzahl der zu lesenden Sequences + sal_Int32 nItemCount = InStream->readLong(); + + for( sal_Int32 i = 0 ; i < nItemCount ; i++ ) + { + insertEntry( i ); + // Laenge der Sequence lesen + sal_Int32 nSeqLen = InStream->readLong(); + + // Sequence anlegen und Descriptoren lesen + Sequence< ScriptEventDescriptor > aSEDSeq( nSeqLen ); + ScriptEventDescriptor* pArray = aSEDSeq.getArray(); + for( sal_Int32 j = 0 ; j < nSeqLen ; j++ ) + { + ScriptEventDescriptor& rDesc = pArray[ j ]; + rDesc.ListenerType = InStream->readUTF(); + rDesc.EventMethod = InStream->readUTF(); + rDesc.AddListenerParam = InStream->readUTF(); + rDesc.ScriptType = InStream->readUTF(); + rDesc.ScriptCode = InStream->readUTF(); + } + registerScriptEvents( i, aSEDSeq ); + } + + // Haben wir die angegebene Laenge gelesen? + sal_Int32 nRealLen = xMarkStream->offsetToMark( nObjLenMark ); + if( nRealLen != nLen ) + { + // Nur wenn die StreamVersion > 1 ist und noch Daten folgen, kann das + // Ganze richtig sein. Sonst ist etwas voellig daneben gegangen. + if( nRealLen > nLen || nVersion == 1 ) + { + VOS_ENSHURE( sal_False, "ImplEventAttacherManager::read(): Fatal Error, wrong object length" ); + } + else + { + // TODO: Pruefen, ob Zwischen-Speicherung der Daten sinnvoll sein koennte + + // Vorerst einfach nur Skippen + sal_Int32 nSkipCount = nLen - nRealLen; + InStream->skipBytes( nSkipCount ); + } + } + xMarkStream->jumpToFurthest(); + xMarkStream->deleteMark( nObjLenMark ); +} + +} // namesapce comphelper + + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * + * Revision 1.0 29.09.00 09:06:41 fs + ************************************************************************/ + diff --git a/comphelper/source/eventattachermgr/makefile.mk b/comphelper/source/eventattachermgr/makefile.mk new file mode 100644 index 000000000000..0a941cc95354 --- /dev/null +++ b/comphelper/source/eventattachermgr/makefile.mk @@ -0,0 +1,109 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=comphelper +TARGET=evtattmgr + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +#UNOTYPES+= \ +# com.sun.star.io.XObjectInputStream \ +# com.sun.star.io.XPersistObject \ +# com.sun.star.io.XObjectOutputStream \ +# com.sun.star.io.XMarkableStream \ +# com.sun.star.lang.XMultiServiceFactory \ +# com.sun.star.lang.XSingleServiceFactory \ +# com.sun.star.lang.XTypeProvider \ +# com.sun.star.lang.XInitialization \ +# com.sun.star.reflection.XIdlReflection \ +# com.sun.star.beans.XIntrospection \ +# com.sun.star.script.XTypeConverter \ +# com.sun.star.script.XEventAttacher \ +# com.sun.star.script.XEventAttacherManager \ +# com.sun.star.script.XScriptListener \ +# com.sun.star.script.XEngineListener + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/eventattachermgr.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/misc/makefile.mk b/comphelper/source/misc/makefile.mk new file mode 100644 index 000000000000..1584dac075bb --- /dev/null +++ b/comphelper/source/misc/makefile.mk @@ -0,0 +1,86 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=comphelper +TARGET=misc + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/types.obj \ + $(SLO)$/datetime.obj \ + $(SLO)$/numbers.obj \ + $(SLO)$/sequence.obj \ + $(SLO)$/querydeep.obj \ + $(SLO)$/regpathhelper.obj \ + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/misc/numbers.cxx b/comphelper/source/misc/numbers.cxx new file mode 100644 index 000000000000..d9232903967d --- /dev/null +++ b/comphelper/source/misc/numbers.cxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * $RCSfile: numbers.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_NUMBERS_HXX_ +#include <comphelper/numbers.hxx> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_ +#include <com/sun/star/util/NumberFormat.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTYPES_HPP_ +#include <com/sun/star/util/XNumberFormatTypes.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_LOCALE_HPP_ +#include <com/sun/star/lang/Locale.hpp> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +namespace starbeans = ::com::sun::star::beans; +namespace starlang = ::com::sun::star::lang; + +//------------------------------------------------------------------------------ +sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey) +{ + sal_Int16 nReturn(starutil::NumberFormat::UNDEFINED); + if (xFormats.is()) + { + try + { + staruno::Reference<starbeans::XPropertySet> xFormat(xFormats->getByKey(nKey)); + if (xFormat.is()) + xFormat->getPropertyValue(rtl::OUString::createFromAscii("Type")) >>= nReturn; + } + catch(...) + { + OSL_TRACE("getNumberFormatType : invalid key! (maybe created with another formatter ?)"); + } + } + return nReturn; +} + +//------------------------------------------------------------------------------ +sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormatter>& xFormatter, sal_Int32 nKey) +{ + OSL_ENSHURE(xFormatter.is(), "getNumberFormatType : the formatter isn't valid !"); + staruno::Reference<starutil::XNumberFormatsSupplier> xSupplier( xFormatter->getNumberFormatsSupplier()); + OSL_ENSHURE(xSupplier.is(), "getNumberFormatType : the formatter doesn't implement a supplier !"); + staruno::Reference<starutil::XNumberFormats> xFormats( xSupplier->getNumberFormats()); + return getNumberFormatType(xFormats, nKey); +} + +//------------------------------------------------------------------------------ +staruno::Any getNumberFormatDecimals(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey) +{ + if (xFormats.is()) + { + try + { + staruno::Reference<starbeans::XPropertySet> xFormat( xFormats->getByKey(nKey)); + if (xFormat.is()) + { + static ::rtl::OUString PROPERTY_DECIMALS = ::rtl::OUString::createFromAscii("Decimals"); + return xFormat->getPropertyValue(PROPERTY_DECIMALS); + } + } + catch(...) + { + OSL_TRACE("getNumberFormatDecimals : invalid key! (may be created with another formatter ?)"); + } + } + return staruno::makeAny((sal_Int16)0); +} + + +//------------------------------------------------------------------------------ +sal_Int32 getStandardFormat( + const staruno::Reference<starutil::XNumberFormatter>& xFormatter, + sal_Int16 nType, + const starlang::Locale& _rLocale) +{ + staruno::Reference<starutil::XNumberFormatsSupplier> xSupplier( xFormatter.is() ? xFormatter->getNumberFormatsSupplier() : staruno::Reference<starutil::XNumberFormatsSupplier>(NULL)); + staruno::Reference<starutil::XNumberFormats> xFormats( xSupplier.is() ? xSupplier->getNumberFormats() : staruno::Reference<starutil::XNumberFormats>(NULL)); + staruno::Reference<starutil::XNumberFormatTypes> xTypes(xFormats, staruno::UNO_QUERY); + OSL_ENSHURE(xTypes.is(), "getStandardFormat : no format types !"); + + return xTypes.is() ? xTypes->getStandardFormat(nType, _rLocale) : 0; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + diff --git a/comphelper/source/misc/querydeep.cxx b/comphelper/source/misc/querydeep.cxx new file mode 100644 index 000000000000..4d24470cbf4a --- /dev/null +++ b/comphelper/source/misc/querydeep.cxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * $RCSfile: querydeep.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_QUERYDEEPINTERFACE_HXX +#include <comphelper/querydeep.hxx> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif + +//__________________________________________________________________________________________________ + +sal_Bool comphelper::isDerivedFrom( + const ::com::sun::star::uno::Type & rBaseType, + const ::com::sun::star::uno::Type & rType ) +{ + using namespace ::com::sun::star::uno; + + TypeClass eClass = rBaseType.getTypeClass(); + + if (eClass != TypeClass_INTERFACE) + return sal_False; + + // supported TypeClass - do the types match ? + if (eClass != rType.getTypeClass()) + return sal_False; + + sal_Bool bRet; + + // shortcut for simple case + if (rBaseType == ::getCppuType(static_cast<const Reference< XInterface > *>(0))) + { + bRet = sal_True; + } + else + { + // now ask in cppu (aka typelib) + ::typelib_TypeDescription *pBaseTD = 0, *pTD = 0; + + rBaseType. getDescription(&pBaseTD); + rType. getDescription(&pTD); + + // interfaces are assignable to a base + bRet = ::typelib_typedescription_isAssignableFrom(pBaseTD, pTD); + + ::typelib_typedescription_release(pBaseTD); + ::typelib_typedescription_release(pTD); + } + + return bRet; +} + + + diff --git a/comphelper/source/misc/regpathhelper.cxx b/comphelper/source/misc/regpathhelper.cxx new file mode 100644 index 000000000000..8ca3e7e4585f --- /dev/null +++ b/comphelper/source/misc/regpathhelper.cxx @@ -0,0 +1,353 @@ +/************************************************************************* + * + * $RCSfile: regpathhelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> + +#ifndef _OSL_SECURITY_H_ +#include <osl/security.h> +#endif +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _VOS_PROCESS_HXX_ +#include <vos/process.hxx> +#endif +#ifndef _VOS_PROFILE_HXX_ +#include <vos/profile.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + + +#if defined ( UNX ) || defined( MAC ) +#include <limits.h> +#define _MAX_PATH PATH_MAX +#endif + +using namespace vos; +using namespace osl; +using namespace rtl; + +#define PATH_DELEMITTER '/' + +#define USER_REGISTRY_NAME_ENV "STAR_USER_REGISTRY" +#define SYSTEM_REGISTRY_NAME_ENV "STAR_REGISTRY" + +#define SVERSION_NAME "sversion" +#define REGISTRY_SECTION "Registry" +#define REGISTRY_VERSION_KEY "UserRegistry 5.3" +#define REGISTRY_LOCAL_NAME "user53.rdb" +#define REGISTRY_SYSTEM_NAME "applicat.rdb" + +#define LOCALREGISTRY_DEFAULTLOCATION "?^" +#define LOCALREGISTRY_PORTALLOCATION "?#" + +#define SVERSION_LOCATION "?^" +#define SVERSION_FALLBACK "?$" + +namespace comphelper +{ + +static OUString getDefaultLocalRegistry() +{ + OUString uBuffer, userRegistryName; + + OStartupInfo startInfo; + sal_uInt32 nArgs = startInfo.getCommandArgCount(); + sal_Bool bIsPortalUser = sal_False, bFindProfile = sal_False; + OUString sArg; + while( nArgs > 0 ) + { + if ( !startInfo.getCommandArg(nArgs--, sArg) ) + { + if ( sArg.indexOf(OUString::createFromAscii("-userid")) == 0 ) + { + bIsPortalUser = sal_True; + break; + } + } + } + + if ( bIsPortalUser ) + { + bFindProfile = OProfile::getProfileName(uBuffer, + OUString::createFromAscii(REGISTRY_LOCAL_NAME), + OUString::createFromAscii(LOCALREGISTRY_PORTALLOCATION)); + } else + { + bFindProfile = OProfile::getProfileName(uBuffer, + OUString::createFromAscii(REGISTRY_LOCAL_NAME), + OUString::createFromAscii(LOCALREGISTRY_DEFAULTLOCATION)); + } + if ( bFindProfile ) + { + FileBase::getSystemPathFromNormalizedPath(uBuffer, userRegistryName); + } + + return userRegistryName; +} + + +OUString getPathToUserRegistry() +{ + OUString uBuffer; + OUString userRegistryName; + sal_Char buffer[_MAX_PATH]= ""; + FILE *f=NULL; + sal_Bool findProfile = sal_False; + + // search the environment STAR_USER_REGISTRY + OString sBuffer( getenv(USER_REGISTRY_NAME_ENV) ); + if ( sBuffer.getLength() > 0 ) + { + f = fopen( sBuffer.getStr(), "r" ); + + if (f != NULL) + { + fclose(f); + userRegistryName = OStringToOUString( sBuffer, RTL_TEXTENCODING_ASCII_US); + return userRegistryName; + } + } + + // search for entry in sversion.ini in config directory + if ( OProfile::getProfileName( uBuffer, + OUString( RTL_CONSTASCII_USTRINGPARAM(SVERSION_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM(SVERSION_LOCATION) )) ) + { + OProfile profile; + + if ( profile.open(uBuffer) ) + { + findProfile = sal_True; + + OString userRegistryKey( REGISTRY_VERSION_KEY ); + userRegistryKey += "/"; + userRegistryKey += OString::valueOf((sal_Int32)SUPD); + + if ( profile.readString(REGISTRY_SECTION, userRegistryKey.getStr(), buffer, _MAX_PATH, "") ) + { + if ( buffer[0] == '\0' ) + { + if ( profile.readString(REGISTRY_SECTION, REGISTRY_VERSION_KEY, buffer, _MAX_PATH, "") ) + sBuffer = buffer; + } else + { + sBuffer = buffer; + } + } + } + + if ( sBuffer.getLength() > 0 ) + { + f = fopen( sBuffer.getStr(), "r"); + + if (f != NULL) + { + fclose(f); + userRegistryName = OStringToOUString(sBuffer, RTL_TEXTENCODING_ASCII_US); + return userRegistryName; + } + } + } + // search for entry in sversion.ini in system directory + if ( !findProfile && + OProfile::getProfileName( uBuffer, + OUString::createFromAscii(SVERSION_NAME), + OUString::createFromAscii(SVERSION_FALLBACK) )) + { + OProfile profile; + + if ( profile.open(uBuffer) ) + { + OString userRegistryKey(REGISTRY_VERSION_KEY); + userRegistryKey += OString::valueOf(PATH_DELEMITTER); + userRegistryKey += OString::valueOf((sal_Int32)SUPD); + + if ( profile.readString(REGISTRY_SECTION, userRegistryKey.getStr(), buffer, _MAX_PATH, "") ) + { + if (buffer[0] == '\0') + { + if (profile.readString(REGISTRY_SECTION, REGISTRY_VERSION_KEY, buffer, _MAX_PATH, "")) + sBuffer = buffer; + } else + { + sBuffer = buffer; + } + } + } + + if ( sBuffer.getLength() > 0 ) + { + f = fopen( sBuffer.getStr(), "r" ); + + if (f != NULL) + { + fclose(f); + userRegistryName = OStringToOUString(sBuffer, RTL_TEXTENCODING_ASCII_US); + return userRegistryName; + } + } + } + + // default security of logged in user + OSecurity sec; + if ( sec.getConfigDir(uBuffer) && uBuffer.getLength() ) + { + // search without dot + OUString normalizedPath; + if (!FileBase::getSystemPathFromNormalizedPath(uBuffer, normalizedPath)) + { + sBuffer = OUStringToOString(normalizedPath, RTL_TEXTENCODING_ASCII_US); + if ( sBuffer.getLength() > 0 ) + sBuffer += OString::valueOf(PATH_DELEMITTER); + sBuffer += REGISTRY_LOCAL_NAME; + + userRegistryName = OStringToOUString( sBuffer, RTL_TEXTENCODING_ASCII_US); + f = fopen(sBuffer.getStr(), "r"); + + if (f == NULL) + { + // search with dot + sBuffer = OUStringToOString(normalizedPath, RTL_TEXTENCODING_ASCII_US); + if ( sBuffer.getLength() > 0 ) + sBuffer += OString::valueOf(PATH_DELEMITTER); + + sBuffer += "."; + sBuffer += REGISTRY_LOCAL_NAME; + + userRegistryName = OStringToOUString( sBuffer, RTL_TEXTENCODING_ASCII_US); + f = fopen( sBuffer.getStr(), "r" ); + + if (f == NULL) + { + userRegistryName = OUString(); + } + } + + if (f != NULL) + { + fclose(f); + } + } + } + + if ( !userRegistryName.getLength() ) + { + userRegistryName = getDefaultLocalRegistry(); + } + + return userRegistryName; +} + +OUString getPathToSystemRegistry() +{ + OUString uBuffer; + OUString registryBaseName( RTL_CONSTASCII_USTRINGPARAM(REGISTRY_SYSTEM_NAME) ); + OUString systemRegistryName; + FILE *f=NULL; + + // search in the directory of the executable + if( OStartupInfo::E_None == OStartupInfo().getExecutableFile(uBuffer) ) + { + sal_uInt32 lastIndex = uBuffer.lastIndexOf(PATH_DELEMITTER); + if (lastIndex > 0) + { + uBuffer = uBuffer.copy(0, lastIndex + 1); + } + + uBuffer += registryBaseName; + + if (!FileBase::getSystemPathFromNormalizedPath(uBuffer, systemRegistryName)) + { + OString tmpStr( OUStringToOString(systemRegistryName, RTL_TEXTENCODING_ASCII_US) ); + f = fopen( tmpStr.getStr(), "r" ); + } + } + + if (f == NULL) + { + // search the environment STAR_REGISTRY + OString tmpStr( getenv(SYSTEM_REGISTRY_NAME_ENV) ); + if ( tmpStr.getLength() > 0 ) + { + f = fopen(tmpStr.getStr(), "r"); + + if (f != NULL) + { + fclose(f); + systemRegistryName = OStringToOUString( tmpStr, RTL_TEXTENCODING_ASCII_US); + } else + { + systemRegistryName = OUString(); + } + } + } else + { + fclose(f); + } + + return systemRegistryName; +} + +} + diff --git a/comphelper/source/misc/sequence.cxx b/comphelper/source/misc/sequence.cxx new file mode 100644 index 000000000000..5b9e8b5fdae7 --- /dev/null +++ b/comphelper/source/misc/sequence.cxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * $RCSfile: sequence.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_SEQUENCE_HXX_ +#include <comphelper/sequence.hxx> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//------------------------------------------------------------------------------ +staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst) +{ + sal_Int32 nLength = _rList.getLength(); + + if( _bOnlyFirst ) + { + ////////////////////////////////////////////////////////////////////// + // An welcher Position finde ich den Wert? + sal_Int32 nPos = -1; + const ::rtl::OUString* pTArray = _rList.getConstArray(); + for (sal_uInt32 i = 0; i < nLength; ++i, ++pTArray) + { + if( pTArray->equals(_rValue) ) + { + nPos = i; + break; + } + } + + ////////////////////////////////////////////////////////////////////// + // Sequence fuellen + if( nPos>-1 ) + { + staruno::Sequence<sal_Int16> aRetSeq( 1 ); + aRetSeq.getArray()[0] = (sal_Int16)nPos; + + return aRetSeq; + } + + return staruno::Sequence<sal_Int16>(); + + } + else + { + staruno::Sequence<sal_Int16> aRetSeq( nLength ); + sal_Int16* pReturn = aRetSeq.getArray(); + + ////////////////////////////////////////////////////////////////////// + // Wie oft kommt der Wert vor? + const ::rtl::OUString* pTArray = _rList.getConstArray(); + for (sal_uInt32 i = 0; i < nLength; ++i, ++pTArray) + { + if( pTArray->equals(_rValue) ) + { + *pReturn = (sal_Int16)i; + ++pReturn; + } + } + + aRetSeq.realloc(pReturn - aRetSeq.getArray()); + + return aRetSeq; + } +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + diff --git a/comphelper/source/misc/types.cxx b/comphelper/source/misc/types.cxx new file mode 100644 index 000000000000..fe991ad6371d --- /dev/null +++ b/comphelper/source/misc/types.cxx @@ -0,0 +1,478 @@ +/************************************************************************* + * + * $RCSfile: types.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_TYPES_HXX_ +#include <comphelper/types.hxx> +#endif +#ifndef _COMPHELPER_DATETIME_HXX_ +#include <comphelper/datetime.hxx> +#endif + +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +#ifndef _COM_SUN_STAR_UTIL_DATE_HPP_ +#include <com/sun/star/util/Date.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_TIME_HPP_ +#include <com/sun/star/util/Time.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_ +#include <com/sun/star/util/DateTime.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_FONTUNDERLINE_HPP_ +#include <com/sun/star/awt/FontUnderline.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_FONTSTRIKEOUT_HPP_ +#include <com/sun/star/awt/FontStrikeout.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_ +#include <com/sun/star/awt/FontDescriptor.hpp> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#include <memory.h> + + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +// namespace starutil = ::com::sun::star::util; + +//------------------------------------------------------------------------------ +sal_Int32 getINT32(const staruno::Any& _rAny) +{ + sal_Int32 nReturn; + _rAny >>= nReturn; + return nReturn; +} + +//------------------------------------------------------------------------------ +sal_Int16 getINT16(const staruno::Any& _rAny) +{ + sal_Int16 nReturn; + _rAny >>= nReturn; + return nReturn; +} + +//------------------------------------------------------------------------------ +double getDouble(const staruno::Any& _rAny) +{ + double nReturn; + _rAny >>= nReturn; + return nReturn; +} + +//------------------------------------------------------------------------------ +float getFloat(const staruno::Any& _rAny) +{ + float nReturn; + _rAny >>= nReturn; + return nReturn; +} + +//------------------------------------------------------------------------------ +::rtl::OUString getString(const staruno::Any& _rAny) +{ + ::rtl::OUString nReturn; + _rAny >>= nReturn; + return nReturn; +} + +//------------------------------------------------------------------------------ +sal_Bool getBOOL(const staruno::Any& _rAny) +{ + sal_Bool nReturn = sal_False; + if (_rAny.getValueType() == ::getCppuBooleanType()) + nReturn = *(sal_Bool*)_rAny.getValue(); + else + OSL_ENSHURE(sal_False, "comphelper::getBOOL : invalid argument !"); + return nReturn; +} + +//------------------------------------------------------------------------------ +sal_Int32 getEnumAsINT32(const staruno::Any& _rAny) throw(starlang::IllegalArgumentException) +{ + sal_Int32 nReturn; + if (! ::cppu::enum2int(nReturn,_rAny) ) + throw starlang::IllegalArgumentException(); + return nReturn; +} + +//------------------------------------------------------------------------------ +starawt::FontDescriptor getDefaultFont() +{ + starawt::FontDescriptor aReturn; + aReturn.Slant = starawt::FontSlant_DONTKNOW; + aReturn.Underline = starawt::FontUnderline::DONTKNOW; + aReturn.Strikeout = starawt::FontStrikeout::DONTKNOW; + return aReturn; +} + +//------------------------------------------------------------------------------ +sal_Bool isAssignableFrom(const staruno::Type& _rAssignable, const staruno::Type& _rFrom) +{ + // getthe type lib descriptions + typelib_TypeDescription* pAssignable = NULL; + _rAssignable.getDescription(&pAssignable); + + typelib_TypeDescription* pFrom = NULL; + _rFrom.getDescription(&pFrom); + + // and ask the type lib + return typelib_typedescription_isAssignableFrom(pAssignable, pFrom); +} + +//------------------------------------------------------------------ +template<class TYPE> +sal_Bool tryCompare(const void* _pData, const staruno::Any& _rValue, sal_Bool& _bIdentical, TYPE& _rOut) +{ + sal_Bool bSuccess = _rValue >>= _rOut; + _bIdentical = bSuccess && (_rOut == *reinterpret_cast<const TYPE*>(_pData)); + return bSuccess; +} + +//------------------------------------------------------------------ +sal_Bool tryCompare(const void* _pData, const staruno::Any& _rValue, sal_Bool& _bIdentical, sal_Char& _rOut) +{ + sal_Int8 nDummy; + sal_Bool bSuccess = _rValue >>= nDummy; + _rOut = (sal_Char)nDummy; + _bIdentical = bSuccess && (_rOut == *reinterpret_cast<const sal_Bool*>(_pData)); + return bSuccess; +} + +//------------------------------------------------------------------ +sal_Bool compare_impl(const staruno::Type& _rType, const void* pData, const staruno::Any& _rValue) +{ + sal_Bool bRes = sal_True; + + if (_rType.getTypeClass() == staruno::TypeClass_ANY) + { + // beides AnyWerte + if (_rValue.getValueType().getTypeClass() == staruno::TypeClass_ANY) + bRes = compare_impl( + reinterpret_cast<const staruno::Any*>(pData)->getValueType(), + reinterpret_cast<const staruno::Any*>(pData)->getValue(), + *reinterpret_cast<const staruno::Any*>(_rValue.getValue())); + else + bRes = compare_impl( + reinterpret_cast<const staruno::Any*>(pData)->getValueType(), + reinterpret_cast<const staruno::Any*>(pData)->getValue(), + _rValue); + } + else if ( (_rType.getTypeClass() == staruno::TypeClass_VOID) + || (_rValue.getValueType().getTypeClass() == staruno::TypeClass_VOID) + ) + { + bRes = _rType.getTypeClass() == _rValue.getValueType().getTypeClass(); + } + else + { + sal_Bool bConversionSuccess = sal_False; + switch (_rType.getTypeClass()) + { + case staruno::TypeClass_VOID: + bConversionSuccess = sal_True; + bRes = _rValue.getValueType().getTypeClass() == staruno::TypeClass_VOID; + break; + case staruno::TypeClass_BOOLEAN: + { + sal_Bool aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_CHAR: + { + sal_Char aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_STRING: + { + ::rtl::OUString aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_FLOAT: + { + float aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_DOUBLE: + { + double aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_BYTE: + { + sal_Int8 aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_SHORT: + { + sal_Int16 aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_ENUM: + { + sal_Int32 nAsInt32; + bConversionSuccess = ::cppu::enum2int(nAsInt32, _rValue); + bRes = bConversionSuccess && (nAsInt32== *reinterpret_cast<const sal_Int32*>(pData)); + break; + } + case staruno::TypeClass_LONG: + { + sal_Int32 aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_UNSIGNED_SHORT: + { + sal_uInt16 aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_UNSIGNED_LONG: + { + sal_uInt32 aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_INTERFACE: + { + InterfaceRef aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + case staruno::TypeClass_STRUCT: + if (isA(_rType, static_cast<starawt::FontDescriptor*>(NULL))) + { + starawt::FontDescriptor aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + bRes = *(starawt::FontDescriptor*)pData == aTemp; + } + else + bRes = sal_False; + break; + } + if (isA(_rType, static_cast<starutil::Date*>(NULL))) + { + starutil::Date aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + if (isA(_rType, static_cast<starutil::Time*>(NULL))) + { + starutil::Time aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + if (isA(_rType, static_cast<starutil::DateTime*>(NULL))) + { + starutil::DateTime aDummy; + bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy); + break; + } + break; + case staruno::TypeClass_SEQUENCE: + if (isA(_rType, static_cast< staruno::Sequence<sal_Int8>* >(NULL))) + { + staruno::Sequence<sal_Int8> aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence<sal_Int8>& rLeftSeq = *reinterpret_cast<const staruno::Sequence<sal_Int8>*>(pData); + const staruno::Sequence<sal_Int8>& rRightSeq = aTemp; + bRes = rLeftSeq.getLength() == rRightSeq.getLength() && + memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()) == 0; + } + } + else if (isA(_rType, static_cast< staruno::Sequence<sal_uInt8>* >(NULL))) + { + staruno::Sequence<sal_uInt8> aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence<sal_uInt8>& rLeftSeq = *reinterpret_cast<const staruno::Sequence<sal_uInt8>*>(pData); + const staruno::Sequence<sal_uInt8>& rRightSeq = aTemp; + bRes = rLeftSeq.getLength() == rRightSeq.getLength() && + memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()) == 0; + } + } + else if (isA(_rType, static_cast< staruno::Sequence<sal_Int16>* >(NULL))) + { + staruno::Sequence<sal_Int16> aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence<sal_Int16>& rLeftSeq = *reinterpret_cast<const staruno::Sequence<sal_Int16>*>(pData); + const staruno::Sequence<sal_Int16>& rRightSeq = aTemp; + bRes = rLeftSeq.getLength() == rRightSeq.getLength() && + memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_Int16)) == 0; + } + } + else if (isA(_rType, static_cast< staruno::Sequence<sal_uInt16>* >(NULL))) + { + staruno::Sequence<sal_uInt16> aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence<sal_uInt16>& rLeftSeq = *reinterpret_cast<const staruno::Sequence<sal_uInt16>*>(pData); + const staruno::Sequence<sal_uInt16>& rRightSeq = aTemp; + bRes = rLeftSeq.getLength() == rRightSeq.getLength() && + memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_uInt16)) == 0; + } + } + else if (isA(_rType, static_cast< staruno::Sequence<sal_Int32>* >(NULL))) + { + staruno::Sequence<sal_Int32> aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence<sal_Int32>& rLeftSeq = *reinterpret_cast<const staruno::Sequence<sal_Int32>*>(pData); + const staruno::Sequence<sal_Int32>& rRightSeq = aTemp; + bRes = rLeftSeq.getLength() == rRightSeq.getLength() && + memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_Int32)) == 0; + } + } + else if (isA(_rType, static_cast< staruno::Sequence<sal_uInt32>* >(NULL))) + { + staruno::Sequence<sal_uInt32> aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence<sal_uInt32>& rLeftSeq = *reinterpret_cast<const staruno::Sequence<sal_uInt32>*>(pData); + const staruno::Sequence<sal_uInt32>& rRightSeq = aTemp; + bRes = rLeftSeq.getLength() == rRightSeq.getLength() && + memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_uInt32)) == 0; + } + } + else if (isA(_rType, static_cast< staruno::Sequence< ::rtl::OUString >* >(NULL))) + { + staruno::Sequence< ::rtl::OUString > aTemp; + bConversionSuccess = _rValue >>= aTemp; + if (bConversionSuccess) + { + const staruno::Sequence< ::rtl::OUString >& rLeftSeq = *reinterpret_cast<const staruno::Sequence< ::rtl::OUString>*>(pData); + const staruno::Sequence< ::rtl::OUString >& rRightSeq = aTemp; + sal_uInt32 nSeqLen = rLeftSeq.getLength(); + bRes = ( nSeqLen == rRightSeq.getLength() ); + for ( sal_uInt32 n = 0; bRes && ( n < nSeqLen ); n++ ) + { + const ::rtl::OUString& rS1 = rLeftSeq.getConstArray()[n]; + const ::rtl::OUString& rS2 = rRightSeq.getConstArray()[n]; + bRes = ( rS1 == rS2 ); + } + } + } + break; + default: + bRes = sal_False; + } + + bRes = bRes && bConversionSuccess; + } + return bRes; +} + +//------------------------------------------------------------------------------ +sal_Bool compare(const staruno::Any& rLeft, const staruno::Any& rRight) +{ + return compare_impl(rLeft.getValueType(), rLeft.getValue(), rRight); +} + +//------------------------------------------------------------------------- +sal_Bool operator ==(const starawt::FontDescriptor& _rLeft, const starawt::FontDescriptor& _rRight) +{ + return ( _rLeft.Name.equals( _rRight.Name ) ) && + ( _rLeft.Height == _rRight.Height ) && + ( _rLeft.Width == _rRight.Width ) && + ( _rLeft.StyleName.equals( _rRight.StyleName ) ) && + ( _rLeft.Family == _rRight.Family ) && + ( _rLeft.CharSet == _rRight.CharSet ) && + ( _rLeft.Pitch == _rRight.Pitch ) && + ( _rLeft.CharacterWidth == _rRight.CharacterWidth ) && + ( _rLeft.Weight == _rRight.Weight ) && + ( _rLeft.Slant == _rRight.Slant ) && + ( _rLeft.Underline == _rRight.Underline ) && + ( _rLeft.Strikeout == _rRight.Strikeout ) && + ( _rLeft.Orientation == _rRight.Orientation ) && + ( _rLeft.Kerning == _rRight.Kerning ) && + ( _rLeft.WordLineMode == _rRight.WordLineMode ) && + ( _rLeft.Type == _rRight.Type ) ; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + diff --git a/comphelper/source/processfactory/componentfactory.cxx b/comphelper/source/processfactory/componentfactory.cxx new file mode 100644 index 000000000000..b0006eb10427 --- /dev/null +++ b/comphelper/source/processfactory/componentfactory.cxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * $RCSfile: componentfactory.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_COMPONENTFACTORY_HXX +#include <comphelper/componentfactory.hxx> +#endif +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <comphelper/processfactory.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HDL_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif + +#ifndef _UNO_ENVIRONMENT_H_ +#include <uno/environment.h> +#endif +#ifndef _UNO_MAPPING_HXX_ +#include <uno/mapping.hxx> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _OSL_MODULE_H_ +#include <osl/module.h> +#endif + + +#pragma hdrstop + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::rtl; + + +namespace comphelper +{ + +Reference< XInterface > getComponentInstance( + const OUString & rLibraryName, + const OUString & rImplementationName + ) +{ + Reference< XInterface > xI; + Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); + if ( xMSF.is() ) + xI = xMSF->createInstance( rImplementationName ); + if( !xI.is() ) + { + Reference< XSingleServiceFactory > xSSF = + loadLibComponentFactory( rLibraryName, rImplementationName, + Reference< XMultiServiceFactory >(), Reference< XRegistryKey >() ); + xI = xSSF->createInstance(); + } + return xI; +} + + +Reference< XSingleServiceFactory > loadLibComponentFactory( + const OUString & rLibName, + const OUString & rImplName, + const Reference< XMultiServiceFactory > & xSF, + const Reference< XRegistryKey > & xKey + ) +{ + Reference< XSingleServiceFactory > xRet; + + oslModule lib = osl_loadModule( rLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL ); + if (lib) + { + void * pSym; + + // ========================= LATEST VERSION ========================= + OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) ); + if (pSym = osl_getSymbol( lib, aGetEnvName.pData )) + { + uno_Environment * pCurrentEnv = 0; + uno_Environment * pEnv = 0; + const sal_Char * pEnvTypeName = 0; + (*((component_getImplementationEnvironmentFunc)pSym))( &pEnvTypeName, &pEnv ); + + sal_Bool bNeedsMapping = + (pEnv || 0 != rtl_str_compare( pEnvTypeName, CPPU_CURRENT_LANGUAGE_BINDING_NAME )); + + OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) ); + + if (bNeedsMapping) + { + if (! pEnv) + uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 ); + if (pEnv) + { + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 ); + if (pCurrentEnv) + bNeedsMapping = (pEnv != pCurrentEnv); + } + } + + OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) ); + if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) + { + OString aImplName( OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) ); + + if (bNeedsMapping) + { + if (pEnv && pCurrentEnv) + { + Mapping aCurrent2Env( pCurrentEnv, pEnv ); + Mapping aEnv2Current( pEnv, pCurrentEnv ); + + if (aCurrent2Env.is() && aEnv2Current.is()) + { + void * pSMgr = aCurrent2Env.mapInterface( + xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ); + void * pKey = aCurrent2Env.mapInterface( + xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) ); + + void * pSSF = (*((component_getFactoryFunc)pSym))( + aImplName.getStr(), pSMgr, pKey ); + + if (pKey) + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pKey ); + if (pSMgr) + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSMgr ); + + if (pSSF) + { + aEnv2Current.mapInterface( + reinterpret_cast< void ** >( &xRet ), + pSSF, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) ); + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSSF ); + } + } + } + } + else + { + XSingleServiceFactory * pRet = (XSingleServiceFactory *) + (*((component_getFactoryFunc)pSym))( + aImplName.getStr(), xSF.get(), xKey.get() ); + if (pRet) + { + xRet = pRet; + pRet->release(); + } + } + } + + if (pEnv) + (*pEnv->release)( pEnv ); + if (pCurrentEnv) + (*pCurrentEnv->release)( pCurrentEnv ); + } + + + if (! xRet.is()) + osl_unloadModule( lib ); + } + + return xRet; +} + +} // namespace comphelper diff --git a/comphelper/source/processfactory/makefile.mk b/comphelper/source/processfactory/makefile.mk new file mode 100644 index 000000000000..788d6f61719e --- /dev/null +++ b/comphelper/source/processfactory/makefile.mk @@ -0,0 +1,96 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=comphelper +TARGET=processfactory + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +#UNOTYPES+= \ +# com.sun.star.uno.TypeClass \ +# com.sun.star.lang.XMultiServiceFactory + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/processfactory.obj \ + $(SLO)$/componentfactory.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/processfactory/processfactory.cxx b/comphelper/source/processfactory/processfactory.cxx new file mode 100644 index 000000000000..1c24d57f3540 --- /dev/null +++ b/comphelper/source/processfactory/processfactory.cxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * $RCSfile: processfactory.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <comphelper/processfactory.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace osl; + +namespace comphelper +{ + +/* + This function preserves only that the xProcessFactory variable will not be create when + the library is loaded. +*/ +Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet ) +{ + Guard< Mutex > aGuard( Mutex::getGlobalMutex() ); + + static Reference< XMultiServiceFactory > xProcessFactory; + if ( bSet ) + { + xProcessFactory = xSMgr; + } + + return xProcessFactory; +} + + +void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr) +{ + localProcessFactory( xSMgr, sal_True ); +} + +Reference< XMultiServiceFactory > getProcessServiceFactory() +{ + return localProcessFactory( Reference< XMultiServiceFactory >(), sal_False ); +} + +} // namesapce comphelper + diff --git a/comphelper/source/property/makefile.mk b/comphelper/source/property/makefile.mk new file mode 100644 index 000000000000..191aa0fe3d51 --- /dev/null +++ b/comphelper/source/property/makefile.mk @@ -0,0 +1,85 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=comphelper +TARGET=property + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/propagg.obj \ + $(SLO)$/property.obj \ + $(SLO)$/propmultiplex.obj \ + $(SLO)$/propstate.obj \ + $(SLO)$/propertycontainer.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/property/propagg.cxx b/comphelper/source/property/propagg.cxx new file mode 100644 index 000000000000..c622e1718a86 --- /dev/null +++ b/comphelper/source/property/propagg.cxx @@ -0,0 +1,779 @@ +/************************************************************************* + * + * $RCSfile: propagg.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_AGGREGATION_HXX_ +#include <comphelper/propagg.hxx> +#endif +#ifndef _COMPHELPER_PROPERTY_HXX_ +#include <comphelper/property.hxx> +#endif +#ifndef _CPPUHELPER_QUERYINTERFACE_HXX_ +#include <cppuhelper/queryinterface.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//================================================================== +//= OPropertyArrayAggregationHelper +//================================================================== + +//------------------------------------------------------------------------------ +OPropertyArrayAggregationHelper::OPropertyArrayAggregationHelper( + const staruno::Sequence<starbeans::Property>& _rProperties, + const staruno::Sequence<starbeans::Property>& _rAggProperties, + IPropertyInfoService* _pInfoService, + sal_Int32 _nFirstAggregateId) + :m_aProperties(_rProperties) +{ + m_aProperties.realloc(_rProperties.getLength() + _rAggProperties.getLength()); + + const starbeans::Property* pAggregateProps = _rAggProperties.getConstArray(); + const starbeans::Property* pDelegateProps = _rProperties.getConstArray(); + starbeans::Property* pProps = m_aProperties.getArray(); + + // create the map for the delegator properties + sal_Int32 i = 0; + for (; i < _rProperties.getLength(); ++i, ++pDelegateProps) + m_aPropertyAccessors[pDelegateProps->Handle] = internal::OPropertyAccessor(-1, i, sal_False); + + // create the map for the aggregate properties + sal_Int32 nAggregateHandle = _nFirstAggregateId; + sal_Int32 j = 0; + pProps += _rProperties.getLength(); + for (; i < m_aProperties.getLength(); ++i, ++pProps) + { + *pProps = pAggregateProps[j++]; + + sal_Int32 nHandle(-1); + if (_pInfoService) + nHandle = _pInfoService->getPreferedPropertyId(pProps->Name); + + if (-1 == nHandle) + nHandle = nAggregateHandle++; + else + { // check if we alread have a property with the given handle + const starbeans::Property* pPropsTilNow = m_aProperties.getConstArray(); + for (sal_Int32 k=0; k<i; ++k, ++pPropsTilNow) + if (pPropsTilNow->Handle == nHandle) + { // conflicts -> use another one (which we don't check anymore, assuming _nFirstAggregateId was large enough) + nHandle = nAggregateHandle++; + break; + } + } + + m_aPropertyAccessors[nHandle] = internal::OPropertyAccessor(pProps->Handle, i, sal_True); + pProps->Handle = nHandle; + } + pProps = m_aProperties.getArray(); // reset, needed again below + + // sortieren der Properties nach Namen + qsort((void*) pProps, m_aProperties.getLength(), sizeof(starbeans::Property), &PropertyCompare); + + // Positionen in der Map abgleichen + for (i = 0; i < m_aProperties.getLength(); ++i, ++pProps) + m_aPropertyAccessors[pProps->Handle].nPos = i; +} + +//------------------------------------------------------------------ +starbeans::Property OPropertyArrayAggregationHelper::getPropertyByName(const ::rtl::OUString& _rPropertyName) + throw(starbeans::UnknownPropertyException) +{ + starbeans::Property* pProperty = findPropertyByName(_rPropertyName); + + if (!pProperty) + throw starbeans::UnknownPropertyException(); + + return *pProperty; +} + +//------------------------------------------------------------------------------ +sal_Bool OPropertyArrayAggregationHelper::hasPropertyByName(const ::rtl::OUString& _rPropertyName) +{ + return findPropertyByName(_rPropertyName) != NULL; +} + +//------------------------------------------------------------------------------ +starbeans::Property* OPropertyArrayAggregationHelper::findPropertyByName(const ::rtl::OUString& _rName) const +{ + starbeans::Property aSearch; + aSearch.Name = _rName; + + const starbeans::Property* pAry = m_aProperties.getConstArray(); + return (starbeans::Property*) bsearch(&aSearch, + (void*)pAry, + m_aProperties.getLength(), + sizeof(starbeans::Property), + &PropertyCompare); +} + +//------------------------------------------------------------------------------ +sal_Int32 OPropertyArrayAggregationHelper::getHandleByName(const ::rtl::OUString& _rPropertyName) +{ + starbeans::Property* pProperty = findPropertyByName(_rPropertyName); + return pProperty ? pProperty->Handle : -1; +} + +//------------------------------------------------------------------------------ +sal_Bool OPropertyArrayAggregationHelper::fillPropertyMembersByHandle( + ::rtl::OUString* _pPropName, sal_Int16* _pAttributes, sal_Int32 _nHandle) +{ + internal::ConstPropertyAccessorMapIterator i = m_aPropertyAccessors.find(_nHandle); + sal_Bool bRet = i != m_aPropertyAccessors.end(); + if (bRet) + { + const starbeans::Property& rProperty = m_aProperties.getConstArray()[(*i).second.nPos]; + if (_pPropName) + *_pPropName = rProperty.Name; + if (_pAttributes) + *_pAttributes = rProperty.Attributes; + } + return bRet; +} + +//------------------------------------------------------------------------------ +sal_Bool OPropertyArrayAggregationHelper::fillAggregatePropertyInfoByHandle( + ::rtl::OUString* _pPropName, sal_Int32* _pOriginalHandle, sal_Int32 _nHandle) const +{ + internal::ConstPropertyAccessorMapIterator i = m_aPropertyAccessors.find(_nHandle); + sal_Bool bRet = i != m_aPropertyAccessors.end() && (*i).second.bAggregate; + if (bRet) + { + if (_pOriginalHandle) + *_pOriginalHandle = (*i).second.nOriginalHandle; + if (_pPropName) + { + const starbeans::Property& rProperty = m_aProperties.getConstArray()[(*i).second.nPos]; + *_pPropName = rProperty.Name; + } + } + return bRet; +} + + +//------------------------------------------------------------------------------ +staruno::Sequence<starbeans::Property> OPropertyArrayAggregationHelper::getProperties() +{ + return m_aProperties; +} + + +//------------------------------------------------------------------------------ +sal_Int32 OPropertyArrayAggregationHelper::fillHandles( + sal_Int32* _pHandles, const staruno::Sequence< ::rtl::OUString >& _rPropNames ) +{ + sal_Int32 nHitCount = 0; + const ::rtl::OUString* pReqProps = _rPropNames.getConstArray(); + sal_Int32 nReqLen = _rPropNames.getLength(); + + const starbeans::Property* pCur = m_aProperties.getConstArray(); + const starbeans::Property* pEnd = m_aProperties.getConstArray() + m_aProperties.getLength(); + + for( sal_Int32 i = 0; i < nReqLen; ++i ) + { + // Logarithmus ermitteln + sal_uInt32 n = (sal_uInt32)(pEnd - pCur); + sal_Int32 nLog = 0; + while( n ) + { + nLog += 1; + n = n >> 1; + } + + // Anzahl der noch zu suchenden Properties * dem Log2 der verbleibenden + // zu dursuchenden Properties. + if( (nReqLen - i) * nLog >= pEnd - pCur ) + { + // linear search is better + while( pCur < pEnd && pReqProps[i] > pCur->Name ) + { + pCur++; + } + if( pCur < pEnd && pReqProps[i] == pCur->Name ) + { + _pHandles[i] = pCur->Handle; + nHitCount++; + } + else + _pHandles[i] = -1; + } + else + { + // binary search is better + sal_Int32 nCompVal = 1; + const starbeans::Property* pOldEnd = pEnd--; + const starbeans::Property* pMid = pCur; + + while( nCompVal != 0 && pCur <= pEnd ) + { + pMid = (pEnd - pCur) / 2 + pCur; + + nCompVal = pReqProps[i].compareTo( pMid->Name ); + + if( nCompVal > 0 ) + pCur = pMid + 1; + else + pEnd = pMid - 1; + } + + if( nCompVal == 0 ) + { + _pHandles[i] = pMid->Handle; + nHitCount++; + pCur = pMid +1; + } + else if( nCompVal > 0 ) + { + _pHandles[i] = -1; + pCur = pMid + 1; + } + else + { + _pHandles[i] = -1; + pCur = pMid; + } + pEnd = pOldEnd; + } + } + return nHitCount; +} + +//================================================================== +//= OPropertySetAggregationHelper +//================================================================== + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OPropertySetAggregationHelper::queryInterface(const staruno::Type& _rType) throw(staruno::RuntimeException) +{ + staruno::Any aReturn; + + aReturn = OPropertyStateHelper::queryInterface(_rType); + + if (!aReturn.hasValue()) + aReturn = cppu::queryInterface(_rType + ,static_cast<starbeans::XPropertiesChangeListener*>(this) + ,static_cast<starbeans::XVetoableChangeListener*>(this) + ,static_cast<starlang::XEventListener*>(static_cast<starbeans::XPropertiesChangeListener*>(this)) + ); + + return aReturn; +} + +//------------------------------------------------------------------------------ +void OPropertySetAggregationHelper::disposing() +{ + osl::MutexGuard aGuard(rBHelper.rMutex); + + if (m_xAggregateSet.is() && m_bListening) + { + // als einziger Listener anmelden + m_xAggregateMultiSet->removePropertiesChangeListener(this); + m_xAggregateSet->removeVetoableChangeListener(::rtl::OUString(), this); + m_bListening = sal_False; + } + + OPropertyStateHelper::disposing(); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::disposing(const starlang::EventObject& _rSource) throw (staruno::RuntimeException) +{ + OSL_ENSHURE(m_xAggregateSet.is(), "OPropertySetAggregationHelper::disposing : don't have an aggregate anymore !"); + if (_rSource.Source == m_xAggregateSet) + m_bListening = sal_False; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::propertiesChange(const staruno::Sequence<starbeans::PropertyChangeEvent>& _rEvents) throw(staruno::RuntimeException) +{ + OSL_ENSHURE(m_xAggregateSet.is(), "OPropertySetAggregationHelper::propertiesChange : have no aggregate !"); + + sal_Int32 nLen = _rEvents.getLength(); + cppu::IPropertyArrayHelper& rPH = getInfoHelper(); + + if (1 == nLen) + { + const starbeans::PropertyChangeEvent& evt = _rEvents.getConstArray()[0]; + OSL_ENSHURE(evt.PropertyName.getLength() > 0, "OPropertySetAggregationHelper::propertiesChange : invalid event !"); + // we had a bug where this assertion would have us saved a whole day :) (72514) + sal_Int32 nHandle = rPH.getHandleByName( evt.PropertyName ); + if (nHandle != -1) + fire(&nHandle, &evt.NewValue, &evt.OldValue, 1, sal_False); + // if nHandle is -1 the event marks for a (aggregate) property which we hide to callers + } + else + { + sal_Int32* pHandles = new sal_Int32[nLen]; + staruno::Any* pNewValues = new staruno::Any[nLen]; + staruno::Any* pOldValues = new staruno::Any[nLen]; + + const starbeans::PropertyChangeEvent* pEvents = _rEvents.getConstArray(); + sal_Int32 nDest = 0; + for (sal_Int32 nSource=0; nSource<nLen; ++nSource, ++pEvents) + { + sal_Int32 nHandle = rPH.getHandleByName(pEvents->PropertyName); + if (nHandle != -1) + { // same as above : -1 is valid (73247) ... + pHandles[nDest] = nHandle; + pNewValues[nDest] = pEvents->NewValue; + pOldValues[nDest] = pEvents->OldValue; + ++nDest; + } + } + + if (nDest) + fire(pHandles, pNewValues, pOldValues, nDest, sal_False); + + delete[] pHandles; + delete[] pNewValues; + delete[] pOldValues; + } +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::vetoableChange(const starbeans::PropertyChangeEvent& _rEvent) throw(starbeans::PropertyVetoException, staruno::RuntimeException) +{ + OSL_ENSHURE(m_xAggregateSet.is(), "OPropertySetAggregationHelper::vetoableChange : have no aggregate !"); + + cppu::IPropertyArrayHelper& rPH = getInfoHelper(); + + sal_Int32 nHandle = rPH.getHandleByName(_rEvent.PropertyName); + fire(&nHandle, &_rEvent.NewValue, &_rEvent.OldValue, 1, sal_True); +} + +//------------------------------------------------------------------------------ +void OPropertySetAggregationHelper::setAggregation(const staruno::Reference< staruno::XInterface >& _rxDelegate) + throw( starlang::IllegalArgumentException ) +{ + osl::MutexGuard aGuard(rBHelper.rMutex); + + if (m_bListening && m_xAggregateSet.is()) + { + m_xAggregateMultiSet->removePropertiesChangeListener(this); + m_xAggregateSet->removeVetoableChangeListener(::rtl::OUString(), this); + m_bListening = sal_False; + } + + m_xAggregateState = staruno::Reference<starbeans::XPropertyState>(_rxDelegate, staruno::UNO_QUERY); + m_xAggregateSet = staruno::Reference<starbeans::XPropertySet>(_rxDelegate, staruno::UNO_QUERY); + m_xAggregateMultiSet = staruno::Reference<starbeans::XMultiPropertySet>(_rxDelegate, staruno::UNO_QUERY); + m_xAggregateFastSet = staruno::Reference<starbeans::XFastPropertySet>(_rxDelegate, staruno::UNO_QUERY); + + // must support XPropertySet and XMultiPropertySet + if (m_xAggregateSet.is() && !m_xAggregateMultiSet.is()) + { + throw starlang::IllegalArgumentException(); + } +} + +//------------------------------------------------------------------------------ +void OPropertySetAggregationHelper::startListening() +{ + if (!m_bListening && m_xAggregateSet.is()) + { + osl::MutexGuard aGuard(rBHelper.rMutex); + + // als einziger Listener anmelden + staruno::Sequence< ::rtl::OUString > aPropertyNames; + m_xAggregateMultiSet->addPropertiesChangeListener(aPropertyNames, this); + m_xAggregateSet->addVetoableChangeListener(::rtl::OUString(), this); + + m_bListening = sal_True; + } +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::addVetoableChangeListener(const ::rtl::OUString& _rPropertyName, + const staruno::Reference<starbeans::XVetoableChangeListener>& _rxListener) + throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException) +{ + OPropertySetHelper::addVetoableChangeListener(_rPropertyName, _rxListener); + if (!m_bListening) + startListening(); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::addPropertyChangeListener(const ::rtl::OUString& _rPropertyName, + const staruno::Reference<starbeans::XPropertyChangeListener>& _rxListener) + throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException) +{ + OPropertySetHelper::addPropertyChangeListener(_rPropertyName, _rxListener); + if (!m_bListening) + startListening(); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::addPropertiesChangeListener(const staruno::Sequence< ::rtl::OUString >& _rPropertyNames, + const staruno::Reference<starbeans::XPropertiesChangeListener>& _rxListener) + throw(staruno::RuntimeException) +{ + OPropertySetHelper::addPropertiesChangeListener(_rPropertyNames, _rxListener); + if (!m_bListening) + startListening(); +} + +//------------------------------------------------------------------------------ +sal_Int32 OPropertySetAggregationHelper::getOriginalHandle(sal_Int32 nHandle) const +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)const_cast<OPropertySetAggregationHelper*>(this)->getInfoHelper(); + sal_Int32 nOriginalHandle = -1; + rPH.fillAggregatePropertyInfoByHandle(NULL, &nOriginalHandle, nHandle); + return nOriginalHandle; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::setFastPropertyValue(sal_Int32 _nHandle, const staruno::Any& _rValue) + throw( starbeans::UnknownPropertyException, starbeans::PropertyVetoException, + starlang::IllegalArgumentException, starlang::WrappedTargetException, + staruno::RuntimeException) +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)getInfoHelper(); + ::rtl::OUString aPropName; + sal_Int32 nOriginalHandle = -1; + + // does the handle belong to the aggregation ? + if (rPH.fillAggregatePropertyInfoByHandle(&aPropName, &nOriginalHandle, _nHandle)) + if (m_xAggregateFastSet.is()) + m_xAggregateFastSet->setFastPropertyValue(nOriginalHandle, _rValue); + else + m_xAggregateSet->setPropertyValue(aPropName, _rValue); + else + OPropertySetHelper::setFastPropertyValue(_nHandle, _rValue); +} + +//------------------------------------------------------------------------------ +void OPropertySetAggregationHelper::getFastPropertyValue(staruno::Any& rValue, sal_Int32 nHandle) const +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)const_cast<OPropertySetAggregationHelper*>(this)->getInfoHelper(); + ::rtl::OUString aPropName; + sal_Int32 nOriginalHandle = -1; + + if (rPH.fillAggregatePropertyInfoByHandle(&aPropName, &nOriginalHandle, nHandle)) + { + if (m_xAggregateFastSet.is()) + rValue = m_xAggregateFastSet->getFastPropertyValue(nOriginalHandle); + else + rValue = m_xAggregateSet->getPropertyValue(aPropName); + } +} + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OPropertySetAggregationHelper::getFastPropertyValue(sal_Int32 nHandle) + throw( starbeans::UnknownPropertyException, + starlang::WrappedTargetException, + staruno::RuntimeException) +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)getInfoHelper(); + ::rtl::OUString aPropName; + sal_Int32 nOriginalHandle = -1; + staruno::Any aValue; + + if (rPH.fillAggregatePropertyInfoByHandle(&aPropName, &nOriginalHandle, nHandle)) + { + if (m_xAggregateFastSet.is()) + aValue = m_xAggregateFastSet->getFastPropertyValue(nOriginalHandle); + else + aValue = m_xAggregateSet->getPropertyValue(aPropName); + } + else + aValue = OPropertySetHelper::getFastPropertyValue(nHandle); + + return aValue; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( + const staruno::Sequence< ::rtl::OUString >& _rPropertyNames, + const staruno::Sequence<staruno::Any>& _rValues) + throw( starbeans::PropertyVetoException, + starlang::IllegalArgumentException, + starlang::WrappedTargetException, + staruno::RuntimeException) +{ + OSL_ENSHURE( !rBHelper.bInDispose, "OPropertySetAggregationHelper::setPropertyValues : do not use within the dispose call !"); + OSL_ENSHURE( !rBHelper.bDisposed, "OPropertySetAggregationHelper::setPropertyValues : object is disposed" ); + + // check where the properties come from + if (!m_xAggregateSet.is()) + OPropertySetHelper::setPropertyValues(_rPropertyNames, _rValues); + else if (_rPropertyNames.getLength() == 1) // use the more efficient way + setPropertyValue(_rPropertyNames.getConstArray()[0], _rValues.getConstArray()[0]); + else + { + // gehoeren die Properties alle zum aggregierten Object ? + staruno::Reference<starbeans::XPropertySetInfo> xInfo(m_xAggregateSet->getPropertySetInfo()); + const ::rtl::OUString* pNames = _rPropertyNames.getConstArray(); + sal_Int32 nAggCount(0); + sal_Int32 nLen(_rPropertyNames.getLength()); + + for (sal_Int32 i = 0; i < nLen; ++i, ++pNames) + if (xInfo->hasPropertyByName(*pNames)) + nAggCount++; + pNames = _rPropertyNames.getConstArray(); // reset, we'll need it again below ... + + // all properties belong to the aggregate + if (nAggCount == nLen) + m_xAggregateMultiSet->setPropertyValues(_rPropertyNames, _rValues); + + // all properties belong to the aggregating object + else if (nAggCount == 0) + OPropertySetHelper::setPropertyValues(_rPropertyNames, _rValues); + + // mixed + else + { + const staruno::Any* pValues = _rValues.getConstArray(); + staruno::Any* pConvertedValues = NULL; + staruno::Any* pOldValues = NULL; + sal_Int32* pHandles = NULL; + + try + { + // dividing the Names and _rValues + staruno::Sequence< ::rtl::OUString > AggPropertyNames(nAggCount); + ::rtl::OUString* pAggNames = AggPropertyNames.getArray(); + staruno::Sequence<staruno::Any> AggValues(nAggCount); + staruno::Any* pAggValues = AggValues.getArray(); + staruno::Sequence< ::rtl::OUString > OwnPropertyNames(nLen - nAggCount); + ::rtl::OUString* pOwnNames = AggPropertyNames.getArray(); + staruno::Sequence<staruno::Any> OwnValues(nLen - nAggCount); + staruno::Any* pOwnValues = OwnValues.getArray(); + + for (sal_Int32 i = 0, a = 0, o = 0; i < nLen; ++i) + { + if (xInfo->hasPropertyByName(pNames[i])) + { + pAggNames[a] = pNames[i]; + pAggValues[a++] = pValues[i]; + } + else + { + pOwnNames[o] = pNames[i]; + pOwnValues[o++] = pValues[i]; + } + } + + pHandles = new sal_Int32[ nLen - nAggCount ]; + + // get the map table + cppu::IPropertyArrayHelper& rPH = getInfoHelper(); + + // fill the handle array + sal_Int32 nHitCount = rPH.fillHandles( pHandles, OwnPropertyNames ); + if (nHitCount != 0) + { + + staruno::Any * pConvertedValues = new staruno::Any[ nHitCount ]; + staruno::Any * pOldValues = new staruno::Any[ nHitCount ]; + nHitCount = 0; + sal_Int32 i; + + { + // must lock the mutex outside the loop. So all values are consistent. + osl::MutexGuard aGuard( rBHelper.rMutex ); + for( i = 0; i < (nLen - nAggCount); ++i ) + { + if( pHandles[i] != -1 ) + { + sal_Int16 nAttributes; + rPH.fillPropertyMembersByHandle( NULL, &nAttributes, pHandles[i] ); + if( nAttributes & starbeans::PropertyAttribute::READONLY ) + throw starbeans::PropertyVetoException(); + // Will the property change? + if( convertFastPropertyValue( pConvertedValues[ nHitCount ], pOldValues[nHitCount], + pHandles[i], pOwnValues[i] ) ) + { + // only increment if the property really change + pHandles[nHitCount] = pHandles[i]; + nHitCount++; + } + } + } + // release guard to fire events + } + + // fire vetoable events + fire( pHandles, pConvertedValues, pOldValues, nHitCount, sal_True ); + + // setting the agg Properties + m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); + + { + // must lock the mutex outside the loop. + osl::MutexGuard aGuard( rBHelper.rMutex ); + // Loop over all changed properties + for( i = 0; i < nHitCount; i++ ) + { + // Will the property change? + setFastPropertyValue_NoBroadcast( pHandles[i], pConvertedValues[i] ); + } + // release guard to fire events + } + + // fire change events + fire( pHandles, pConvertedValues, pOldValues, nHitCount, sal_False ); + } + else + m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); + + } + catch(...) + { + delete [] pHandles; + delete [] pOldValues; + delete [] pConvertedValues; + throw; + } + + delete [] pHandles; + delete [] pOldValues; + delete [] pConvertedValues; + } + } +} + +// XPropertyState +//------------------------------------------------------------------------------ +starbeans::PropertyState SAL_CALL OPropertySetAggregationHelper::getPropertyState(const ::rtl::OUString& _rPropertyName) + throw(starbeans::UnknownPropertyException, staruno::RuntimeException) +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)getInfoHelper(); + sal_Int32 nHandle = rPH.getHandleByName( _rPropertyName ); + + if (nHandle == -1) + { + throw starbeans::UnknownPropertyException(); + } + + ::rtl::OUString aPropName; + sal_Int32 nOriginalHandle = -1; + if (rPH.fillAggregatePropertyInfoByHandle(&aPropName, &nOriginalHandle, nHandle)) + { + if (m_xAggregateState.is()) + return m_xAggregateState->getPropertyState(_rPropertyName); + else + return starbeans::PropertyState_DIRECT_VALUE; + } + else + return getPropertyStateByHandle(nHandle); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertySetAggregationHelper::setPropertyToDefault(const ::rtl::OUString& _rPropertyName) + throw(starbeans::UnknownPropertyException, staruno::RuntimeException) +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)getInfoHelper(); + sal_Int32 nHandle = rPH.getHandleByName(_rPropertyName); + if (nHandle == -1) + { + throw starbeans::UnknownPropertyException(); + } + + ::rtl::OUString aPropName; + sal_Int32 nOriginalHandle = -1; + if (rPH.fillAggregatePropertyInfoByHandle(&aPropName, &nOriginalHandle, nHandle)) + { + if (m_xAggregateState.is()) + m_xAggregateState->setPropertyToDefault(_rPropertyName); + } + else + setPropertyToDefaultByHandle(nHandle); +} + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OPropertySetAggregationHelper::getPropertyDefault(const ::rtl::OUString& aPropertyName) + throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException) +{ + OPropertyArrayAggregationHelper& rPH = (OPropertyArrayAggregationHelper&)getInfoHelper(); + sal_Int32 nHandle = rPH.getHandleByName( aPropertyName ); + + if (nHandle == -1) + { + throw starbeans::UnknownPropertyException(); + } + + ::rtl::OUString aPropName; + sal_Int32 nOriginalHandle = -1; + if (rPH.fillAggregatePropertyInfoByHandle(&aPropName, &nOriginalHandle, nHandle)) + { + if (m_xAggregateState.is()) + return m_xAggregateState->getPropertyDefault(aPropertyName); + else + return staruno::Any(); + } + else + return getPropertyDefaultByHandle(nHandle); +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + diff --git a/comphelper/source/property/property.cxx b/comphelper/source/property/property.cxx new file mode 100644 index 000000000000..36953d8b80c5 --- /dev/null +++ b/comphelper/source/property/property.cxx @@ -0,0 +1,207 @@ +/************************************************************************* + * + * $RCSfile: property.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _COMPHELPER_PROPERTY_HXX_ +#include <comphelper/property.hxx> +#endif +#ifndef _COMPHELPER_SEQUENCE_HXX_ +#include <comphelper/sequence.hxx> +#endif +#ifndef _COMPHELPER_TYPES_HXX_ +#include <comphelper/types.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif + +//......................................................................... +namespace comphelper +{ + + namespace starlang = ::com::sun::star::lang; + +//------------------------------------------------------------------ +int +#if defined( WNT ) + __cdecl +#endif +#if defined( ICC ) && defined( OS2 ) +_Optlink +#endif + PropertyCompare( const void* pFirst, const void* pSecond) +{ + return ((starbeans::Property*)pFirst)->Name.compareTo(((starbeans::Property*)pSecond)->Name); +} + +//------------------------------------------------------------------ +void copyProperties(const staruno::Reference<starbeans::XPropertySet>& _rxSource, + const staruno::Reference<starbeans::XPropertySet>& _rxDest) +{ + if (!_rxSource.is() || !_rxDest.is()) + { + OSL_ENSHURE(sal_False, "copyProperties : invalid arguments !"); + } + + staruno::Reference< starbeans::XPropertySetInfo > xSourceProps = _rxSource->getPropertySetInfo(); + staruno::Reference< starbeans::XPropertySetInfo > xDestProps = _rxDest->getPropertySetInfo(); + + staruno::Sequence< starbeans::Property > aSourceProps = xSourceProps->getProperties(); + const starbeans::Property* pSourceProps = aSourceProps.getConstArray(); + starbeans::Property aDestProp; + for (sal_Int32 i=0; i<aSourceProps.getLength(); ++i, ++pSourceProps) + { + if ( xDestProps->hasPropertyByName(pSourceProps->Name) + && xDestProps->hasPropertyByName(pSourceProps->Name) + ) + { + try + { + aDestProp = xDestProps->getPropertyByName(pSourceProps->Name); + if (0 == (aDestProp.Attributes & starbeans::PropertyAttribute::READONLY)) + _rxDest->setPropertyValue(pSourceProps->Name, _rxSource->getPropertyValue(pSourceProps->Name)); + } + catch (staruno::Exception&) + { + OSL_ENSHURE(sal_False, "copyProperties : could not transfer at least one of the properties !"); + } + } + } +} + +//------------------------------------------------------------------ +sal_Bool hasProperty(const rtl::OUString& _rName, const staruno::Reference<starbeans::XPropertySet>& _rxSet) +{ + if (_rxSet.is()) + { + // XPropertySetInfoRef xInfo(rxSet->getPropertySetInfo()); + return _rxSet->getPropertySetInfo()->hasPropertyByName(_rName); + } + return sal_False; +} + +//------------------------------------------------------------------ +void RemoveProperty(staruno::Sequence<starbeans::Property>& _rProps, const rtl::OUString& _rPropName) +{ + sal_Int32 nLen = _rProps.getLength(); + + // binaere Suche + starbeans::Property aSearchDummy(_rPropName, 0, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))/*doesn't matter*/, 0); + const starbeans::Property* pProperties = _rProps.getConstArray(); + starbeans::Property* pResult = (starbeans::Property*) bsearch(&aSearchDummy, (void*)pProperties, nLen, sizeof(starbeans::Property), + &PropertyCompare); + + // gefunden ? + if (pResult) + { + OSL_ENSHURE(pResult->Name.equals(_rPropName), "::RemoveProperty Properties nicht sortiert"); + removeElementAt(_rProps, pResult - pProperties); + } +} + +//------------------------------------------------------------------ +void ModifyPropertyAttributes(staruno::Sequence<starbeans::Property>& seqProps, const ::rtl::OUString& sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib) +{ + sal_Int32 nLen = seqProps.getLength(); + + // binaere Suche + starbeans::Property aSearchDummy(sPropName, 0, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))/*doesn't matter*/, 0); + starbeans::Property* pResult = (starbeans::Property*) bsearch(&aSearchDummy, (void*)seqProps.getArray(), nLen, sizeof(starbeans::Property), + &PropertyCompare); + + // gefunden ? + if (pResult) + { + pResult->Attributes |= nAddAttrib; + pResult->Attributes &= ~nRemoveAttrib; + } +} + +//------------------------------------------------------------------ +sal_Bool tryPropertyValue(staruno::Any& _rConvertedValue, staruno::Any& _rOldValue, const staruno::Any& _rValueToSet, staruno::Any& _rCurrentValue, const staruno::Type& _rExpectedType) +{ + sal_Bool bModified(sal_False); + if (_rCurrentValue.getValue() != _rValueToSet.getValue()) + { + if (_rValueToSet.hasValue() && !_rExpectedType.equals(_rValueToSet.getValueType())) + throw starlang::IllegalArgumentException(); + + if (!compare(_rCurrentValue, _rValueToSet)) + { + _rConvertedValue = _rValueToSet; + _rOldValue = _rCurrentValue; + bModified = sal_True; + } + } + return bModified; +} + +//......................................................................... +} +//......................................................................... + diff --git a/comphelper/source/property/propertycontainer.cxx b/comphelper/source/property/propertycontainer.cxx new file mode 100644 index 000000000000..b860bd55f11c --- /dev/null +++ b/comphelper/source/property/propertycontainer.cxx @@ -0,0 +1,454 @@ +/************************************************************************* + * + * $RCSfile: propertycontainer.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_ +#include <comphelper/propertycontainer.hxx> +#endif +#ifndef _COMPHELPER_PROPERTY_HXX_ +#include <comphelper/property.hxx> +#endif + +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif +#ifndef _COM_SUN_STAR_UNO_GENFUNC_H_ +#include <com/sun/star/uno/genfunc.h> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; + +//========================================================================== +//= OPropertyContainer +//========================================================================== +//-------------------------------------------------------------------------- +OPropertyContainer::OPropertyContainer(::cppu::OBroadcastHelper& _rBHelper) + :OPropertyContainer_Base(_rBHelper) + ,m_bAlreadyAccessed(sal_False) +{ +} + +//-------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OPropertyContainer::getTypes() throw (RuntimeException) +{ + // just the types from our one and only base class + ::cppu::OTypeCollection aTypes( + ::getCppuType( static_cast< Reference< XPropertySet >* >(NULL)), + ::getCppuType( static_cast< Reference< XFastPropertySet >* >(NULL)), + ::getCppuType( static_cast< Reference< XMultiPropertySet >* >(NULL)) + ); + return aTypes.getTypes(); +} + +//-------------------------------------------------------------------------- +void OPropertyContainer::registerProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, + sal_Int32 _nAttributes, void* _pPointerToMember, const Type& _rMemberType) +{ + OSL_ENSHURE(!m_bAlreadyAccessed, "OPropertyContainer::registerProperty : invalid call, the property sequence was already accessed !"); + OSL_ENSHURE((_nAttributes & PropertyAttribute::MAYBEVOID) == 0, + "OPropertyContainer::registerProperty : don't use this for properties which may be void ! There is a method called \"registerMayBeVoidProperty\" for this !"); + OSL_ENSHURE(!_rMemberType.equals(::getCppuType(static_cast< Any* >(NULL))), + "OPropertyContainer::registerProperty : don't give my the type of an uno::Any ! Really can't handle this !"); + OSL_ENSHURE(_pPointerToMember, + "OPropertyContainer::registerProperty : you gave me nonsense : the pointer must be non-NULL"); + + PropertyDescription aNewProp; + aNewProp.sName = _rName; + aNewProp.nHandle = _nHandle; + aNewProp.nAttributes = _nAttributes; + aNewProp.eLocated = PropertyDescription::ltDerivedClassRealType; + aNewProp.aLocation.pDerivedClassMember = _pPointerToMember; + aNewProp.aType = _rMemberType; + + implPushBackProperty(aNewProp); +} + +//-------------------------------------------------------------------------- +void OPropertyContainer::registerMayBeVoidProperty(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + Any* _pPointerToMember, const Type& _rExpectedType) +{ + OSL_ENSHURE(!m_bAlreadyAccessed, "OPropertyContainer::registerMayBeVoidProperty : invalid call, the property sequence was already accessed !"); + OSL_ENSHURE((_nAttributes & PropertyAttribute::MAYBEVOID) != 0, + "OPropertyContainer::registerMayBeVoidProperty : why calling this when the attributes say nothing about may-be-void ?"); + OSL_ENSHURE(!_rExpectedType.equals(::getCppuType(static_cast< Any* >(NULL))), + "OPropertyContainer::registerMayBeVoidProperty : don't give my the type of an uno::Any ! Really can't handle this !"); + OSL_ENSHURE(_pPointerToMember, + "OPropertyContainer::registerMayBeVoidProperty : you gave me nonsense : the pointer must be non-NULL"); + + _nAttributes &= PropertyAttribute::MAYBEVOID; + + PropertyDescription aNewProp; + aNewProp.sName = _rName; + aNewProp.nHandle = _nHandle; + aNewProp.nAttributes = _nAttributes; + aNewProp.eLocated = PropertyDescription::ltDerivedClassAnyType; + aNewProp.aLocation.pDerivedClassMember = _pPointerToMember; + aNewProp.aType = _rExpectedType; + + implPushBackProperty(aNewProp); +} + + +//-------------------------------------------------------------------------- +void OPropertyContainer::registerPropertyNoMember(const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, + const Type& _rType, void* _pInitialValue) +{ + OSL_ENSHURE(!m_bAlreadyAccessed, "OPropertyContainer::registerMayBeVoidProperty : invalid call, the property sequence was already accessed !"); + OSL_ENSHURE(!_rType.equals(::getCppuType(static_cast< Any* >(NULL))), + "OPropertyContainer::registerPropertyNoMember : don't give my the type of an uno::Any ! Really can't handle this !"); + OSL_ENSHURE(!_pInitialValue || ((_nAttributes & PropertyAttribute::MAYBEVOID) != 0), + "OPropertyContainer::registerPropertyNoMember : you should not ommit the initial value if the property can't be void ! This will definitivly crash later !"); + + PropertyDescription aNewProp; + aNewProp.sName = _rName; + aNewProp.nHandle = _nHandle; + aNewProp.nAttributes = _nAttributes; + aNewProp.eLocated = PropertyDescription::ltHoldMyself; + aNewProp.aLocation.nOwnClassVectorIndex = m_aHoldProperties.size(); + if (_pInitialValue) + m_aHoldProperties.push_back(Any(_pInitialValue, _rType)); + else + m_aHoldProperties.push_back(Any()); + aNewProp.aType = _rType; + + implPushBackProperty(aNewProp); +} + +//-------------------------------------------------------------------------- +void OPropertyContainer::implPushBackProperty(const PropertyDescription& _rProp) +{ + // need one more element + sal_Int32 nOldLen = m_aProperties.size(); + m_aProperties.resize(nOldLen + 1); + PropertyDescription* pProps = m_aProperties.begin() + nOldLen - 1; + + // search the corect position, shifting the elements to the tail if needed + sal_Int32 nPos = nOldLen; + while (nPos && (_rProp.nHandle < pProps->nHandle)) + { + *(pProps+1) = *pProps; + --pProps; + --nPos; + } + + m_aProperties[nPos] = _rProp; +} + +//-------------------------------------------------------------------------- +sal_Bool OPropertyContainer::convertFastPropertyValue( + Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw (IllegalArgumentException) +{ +#ifdef DBG_UTIL + m_bAlreadyAccessed = sal_True; +#endif + sal_Bool bModified = sal_False; + + // get the property somebody is asking for + PropertiesIterator aPos = searchHandle(_nHandle); + if (aPos == m_aProperties.end()) + { + OSL_ASSERT("OPropertyContainer::convertFastPropertyValue : unknown handle !"); + // should not happen if the derived class has built a correct property set info helper to be used by + // our base class OPropertySetHelper + return bModified; + } + + switch (aPos->eLocated) + { + // similar handling for the two cases where the value is stored in an any + case PropertyDescription::ltHoldMyself: + case PropertyDescription::ltDerivedClassAnyType: + { + sal_Bool bMayBeVoid = ((aPos->nAttributes & PropertyAttribute::MAYBEVOID) != 0); + // argument check + if ( ! ( (bMayBeVoid && !_rValue.hasValue()) // void is allowed if the attribute says so + || (_rValue.getValueType().equals(aPos->aType)) // else the types have to be equal + ) + ) + throw IllegalArgumentException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid value type")), + static_cast< XPropertySet* >(this), + 4); + + Any* pPropContainer = NULL; + // the pointer to the any which holds the property value, no matter if located in the derived clas + // or in out vector + + if (PropertyDescription::ltHoldMyself == aPos->eLocated) + { + OSL_ENSHURE(aPos->aLocation.nOwnClassVectorIndex < m_aHoldProperties.size(), + "OPropertyContainer::convertFastPropertyValue : invalid position !"); + pPropContainer = m_aHoldProperties.begin() + aPos->aLocation.nOwnClassVectorIndex; + } + else + pPropContainer = reinterpret_cast<Any*>(aPos->aLocation.pDerivedClassMember); + + // check if the new value differs from the current one + if (!pPropContainer->hasValue() || !_rValue.hasValue()) + bModified = pPropContainer->hasValue() != _rValue.hasValue(); + else + bModified = !uno_equalData(const_cast<void*>(pPropContainer->getValue()), aPos->aType.getTypeLibType()->pType, const_cast<void*>(_rValue.getValue()), aPos->aType.getTypeLibType()->pType, cpp_queryInterface, cpp_release); + + if (bModified) + { + _rOldValue = *pPropContainer; + _rConvertedValue = _rValue; + } + } + break; + case PropertyDescription::ltDerivedClassRealType: + // here we don't allow MAYBEVOID properties, so the type check is simple + // (remember that we don't support value conversions, so the value type has to be exactly the one + // required for the property) + if (!_rValue.getValueType().equals(aPos->aType)) + throw IllegalArgumentException(); + + bModified = !uno_equalData(aPos->aLocation.pDerivedClassMember, aPos->aType.getTypeLibType()->pType, const_cast<void*>(_rValue.getValue()), aPos->aType.getTypeLibType()->pType, cpp_queryInterface, cpp_release); + if (bModified) + { + _rOldValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aType); + _rConvertedValue = _rValue; + } + break; + } + + return bModified; +} + +//-------------------------------------------------------------------------- +void OPropertyContainer::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception) +{ +#ifdef DBG_UTIL + m_bAlreadyAccessed = sal_True; +#endif + // get the property somebody is asking for + PropertiesIterator aPos = searchHandle(_nHandle); + if (aPos == m_aProperties.end()) + { + OSL_ASSERT("OPropertyContainer::setFastPropertyValue_NoBroadcast : unknown handle !"); + // should not happen if the derived class has built a correct property set info helper to be used by + // our base class OPropertySetHelper + return; + } + + switch (aPos->eLocated) + { + case PropertyDescription::ltHoldMyself: + m_aHoldProperties[aPos->aLocation.nOwnClassVectorIndex] = _rValue; + break; + case PropertyDescription::ltDerivedClassAnyType: + *reinterpret_cast< Any* >(aPos->aLocation.pDerivedClassMember) = _rValue; + break; + case PropertyDescription::ltDerivedClassRealType: + OSL_ENSHURE(_rValue.getValueType().equals(aPos->aType), + "OPropertyContainer::setFastPropertyValue_NoBroadcast : ooops .... the value is of the wrong type !"); + uno_type_copyData(aPos->aLocation.pDerivedClassMember, const_cast<void*>(_rValue.getValue()), aPos->aType.getTypeLibType(), cpp_acquire); + break; + } +} + +//-------------------------------------------------------------------------- +void OPropertyContainer::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const +{ +#ifdef DBG_UTIL + const_cast<OPropertyContainer*>(this)->m_bAlreadyAccessed = sal_True; + // (are we allowed to use the mutable keyword? Means do all our compilers support this meanwhile?) +#endif + + // get the property somebody is asking for + PropertiesIterator aPos = const_cast<OPropertyContainer*>(this)->searchHandle(_nHandle); + if (aPos == m_aProperties.end()) + { + OSL_ASSERT("OPropertyContainer::getFastPropertyValue : unknown handle !"); + // should not happen if the derived class has built a correct property set info helper to be used by + // our base class OPropertySetHelper + return; + } + + switch (aPos->eLocated) + { + case PropertyDescription::ltHoldMyself: + OSL_ENSHURE(aPos->aLocation.nOwnClassVectorIndex < m_aHoldProperties.size(), + "OPropertyContainer::convertFastPropertyValue : invalid position !"); + _rValue = m_aHoldProperties[aPos->aLocation.nOwnClassVectorIndex]; + break; + case PropertyDescription::ltDerivedClassAnyType: + _rValue = *reinterpret_cast<Any*>(aPos->aLocation.pDerivedClassMember); + break; + case PropertyDescription::ltDerivedClassRealType: + _rValue.setValue(aPos->aLocation.pDerivedClassMember, aPos->aType); + break; + } +} + +//-------------------------------------------------------------------------- +OPropertyContainer::PropertiesIterator OPropertyContainer::searchHandle(sal_Int32 _nHandle) +{ + PropertyDescriptionCompareByHandle aCompareOp; + PropertyDescription aSearch; + aSearch.nHandle = _nHandle; + + // search a lower bound + PropertiesIterator aLowerBound = ::std::lower_bound( + m_aProperties.begin(), + m_aProperties.end(), + aSearch, + aCompareOp); + + // check for identity + if ((aLowerBound != m_aProperties.end()) && aLowerBound->nHandle != _nHandle) + aLowerBound = m_aProperties.end(); + + return aLowerBound; +} + +//-------------------------------------------------------------------------- +void OPropertyContainer::modifyAttributes(sal_Int32 _nHandle, sal_Int32 _nAddAttrib, sal_Int32 _nRemoveAttrib) +{ + OSL_ENSHURE(!m_bAlreadyAccessed, "OPropertyContainer::modifyAttributes : invalid call, the property sequence was already accessed !"); + + // get the property somebody is asking for + PropertiesIterator aPos = searchHandle(_nHandle); + if (aPos == m_aProperties.end()) + { + OSL_ASSERT("OPropertyContainer::modifyAttributes : invalid handle !"); + // should not happen if the derived class has built a correct property set info helper to be used by + // our base class OPropertySetHelper + return; + } + aPos->nHandle |= _nAddAttrib; + aPos->nHandle &= ~_nRemoveAttrib; +} + +//-------------------------------------------------------------------------- +// comparing two property instances +struct PropertyCompareByName : public ::std::binary_function< Property, Property, sal_Bool > +{ + bool operator() (const Property& x, const Property& y) const + { + return x.Name < y.Name; + } +}; + +//.......................................................................... +void OPropertyContainer::describeProperties(Sequence< Property >& _rProps) const +{ + Sequence< Property > aOwnProps(m_aProperties.size()); + Property* pOwnProps = aOwnProps.getArray(); + + for ( ConstPropertiesIterator aLoop = m_aProperties.begin(); + aLoop != m_aProperties.end(); + ++aLoop, ++pOwnProps + ) + { + pOwnProps->Name = aLoop->sName; + pOwnProps->Handle = aLoop->nHandle; + pOwnProps->Attributes = aLoop->nAttributes; + pOwnProps->Type = aLoop->aType; + } + + // as our property vector is sorted by handles, not by name, we have to sort aOwnProps + qsort(aOwnProps.getArray(), aOwnProps.getLength(), sizeof(Property), PropertyCompare); + + // unfortunally the STL merge function does not allow the output range to overlap one of the input ranges, + // so we need an extra sequence + Sequence< Property > aOutput; + aOutput.realloc(_rProps.getLength() + aOwnProps.getLength()); + // do the merge + ::std::merge( _rProps.getConstArray(), _rProps.getConstArray() + _rProps.getLength(), // input 1 + aOwnProps.getConstArray(), aOwnProps.getConstArray() + aOwnProps.getLength(), // input 2 + aOutput.getArray(), // output + PropertyCompareByName() // compare operator + ); + + // copy the output + _rProps = aOutput; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + +/************************************************************************* + * history: + * $Log: not supported by cvs2svn $ + * Revision 1.1 2000/09/21 08:52:22 fs + * base class for classes which are simple property containers + * + * + * Revision 1.0 21.09.00 08:23:50 fs + ************************************************************************/ + diff --git a/comphelper/source/property/propmultiplex.cxx b/comphelper/source/property/propmultiplex.cxx new file mode 100644 index 000000000000..12a7ee4abb85 --- /dev/null +++ b/comphelper/source/property/propmultiplex.cxx @@ -0,0 +1,170 @@ +/************************************************************************* + * + * $RCSfile: propmultiplex.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ +#include <comphelper/propmultiplex.hxx> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//======================================================================== +//= OPropertyChangeListener +//======================================================================== +//------------------------------------------------------------------------ +OPropertyChangeListener::~OPropertyChangeListener() +{ + if (m_pAdapter) + m_pAdapter->dispose(); +} + +//------------------------------------------------------------------ +void OPropertyChangeListener::setAdapter(OPropertyChangeMultiplexer* pAdapter) +{ + if (m_pAdapter) + { + ::osl::MutexGuard aGuard(m_rMutex); + m_pAdapter->release(); + m_pAdapter = NULL; + } + + if (pAdapter) + { + ::osl::MutexGuard aGuard(m_rMutex); + m_pAdapter = pAdapter; + m_pAdapter->acquire(); + } +} + +//======================================================================== +//= OPropertyChangeMultiplexer +//======================================================================== +//------------------------------------------------------------------ +OPropertyChangeMultiplexer::OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const staruno::Reference<starbeans::XPropertySet>& _rxSet) + :m_xSet(_rxSet) + ,m_pListener(_pListener) +{ + m_pListener->setAdapter(this); +} + +//------------------------------------------------------------------ +OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer() +{ +} + +//------------------------------------------------------------------ +void OPropertyChangeMultiplexer::dispose() +{ + if (m_xSet.is()) + { + staruno::Reference<starbeans::XPropertyChangeListener> xPreventDelete(this); + + const ::rtl::OUString* pProperties = m_aProperties.getConstArray(); + for (sal_Int32 i = 0; i < m_aProperties.getLength(); ++i, ++pProperties) + m_xSet->removePropertyChangeListener(*pProperties, static_cast<starbeans::XPropertyChangeListener*>(this)); + + m_pListener->setAdapter(NULL); + + m_xSet = NULL; + m_pListener = NULL; + } +} + +// XEventListener +//------------------------------------------------------------------ +void SAL_CALL OPropertyChangeMultiplexer::disposing( const starlang::EventObject& Source ) throw(staruno::RuntimeException) +{ + if (m_pListener) + m_pListener->setAdapter(NULL); + + m_xSet = NULL; + m_pListener = NULL; +} + +// XPropertyChangeListener +//------------------------------------------------------------------ +void SAL_CALL OPropertyChangeMultiplexer::propertyChange( const starbeans::PropertyChangeEvent& _rEvent ) throw(staruno::RuntimeException) +{ + if (m_pListener) + m_pListener->_propertyChanged(_rEvent); +} + +//------------------------------------------------------------------ +void OPropertyChangeMultiplexer::addProperty(const ::rtl::OUString& _sPropertyName) +{ + if (m_xSet.is()) + { + m_xSet->addPropertyChangeListener(_sPropertyName, static_cast<starbeans::XPropertyChangeListener*>(this)); + m_aProperties.realloc(m_aProperties.getLength() + 1); + m_aProperties.getArray()[m_aProperties.getLength()-1] = _sPropertyName; + } +} + +//......................................................................... +} +//......................................................................... + diff --git a/comphelper/source/property/propstate.cxx b/comphelper/source/property/propstate.cxx new file mode 100644 index 000000000000..d888ba4420b4 --- /dev/null +++ b/comphelper/source/property/propstate.cxx @@ -0,0 +1,202 @@ +/************************************************************************* + * + * $RCSfile: propstate.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_PROPERTY_STATE_HXX_ +#include <comphelper/propstate.hxx> +#endif + +#ifndef _CPPUHELPER_QUERYINTERFACE_HXX_ +#include <cppuhelper/queryinterface.hxx> +#endif + +//......................................................................... +namespace comphelper +{ + +//============================================================================== +// OPropertyStateHelper +//============================================================================== + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OPropertyStateHelper::queryInterface(const staruno::Type& _rType) throw(staruno::RuntimeException) +{ + staruno::Any aReturn; + // ask the base class + aReturn = OPropertySetHelper::queryInterface(_rType); + // our own ifaces + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, static_cast<starbeans::XPropertyState*>(this)); + + return aReturn; +} + +//------------------------------------------------------------------------------ +staruno::Sequence<staruno::Type> OPropertyStateHelper::getTypes() throw(staruno::RuntimeException) +{ + static staruno::Sequence<staruno::Type> aTypes; + if (!aTypes.getLength()) + { + aTypes.realloc(4); + staruno::Type* pTypes = aTypes.getArray(); + // base class types + pTypes[0] = getCppuType((staruno::Reference<starbeans::XPropertySet>*)NULL); + pTypes[1] = getCppuType((staruno::Reference<starbeans::XMultiPropertySet>*)NULL); + pTypes[2] = getCppuType((staruno::Reference<starbeans::XFastPropertySet>*)NULL); + // my own type + pTypes[3] = getCppuType((staruno::Reference<starbeans::XPropertyState>*)NULL); + } + return aTypes; +} + +//------------------------------------------------------------------------------ +void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const staruno::Any& aNewValue, const staruno::Any& aOldValue) +{ + fire(&nHandle, &aNewValue, &aOldValue, 1, sal_False); +} + +// XPropertyState +//------------------------------------------------------------------------------ +starbeans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const ::rtl::OUString& _rsName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException) +{ + cppu::IPropertyArrayHelper& rPH = getInfoHelper(); + sal_Int32 nHandle = rPH.getHandleByName(_rsName); + + if (nHandle == -1) + throw starbeans::UnknownPropertyException(); + + return getPropertyStateByHandle(nHandle); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const ::rtl::OUString& _rsName) throw(starbeans::UnknownPropertyException, staruno::RuntimeException) +{ + cppu::IPropertyArrayHelper& rPH = getInfoHelper(); + sal_Int32 nHandle = rPH.getHandleByName(_rsName); + + if (nHandle == -1) + throw starbeans::UnknownPropertyException(); + + setPropertyToDefaultByHandle(nHandle); +} + +//------------------------------------------------------------------------------ +staruno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const ::rtl::OUString& _rsName) throw(starbeans::UnknownPropertyException, starlang::WrappedTargetException, staruno::RuntimeException) +{ + cppu::IPropertyArrayHelper& rPH = getInfoHelper(); + sal_Int32 nHandle = rPH.getHandleByName(_rsName); + + if (nHandle == -1) + throw starbeans::UnknownPropertyException(); + + return getPropertyDefaultByHandle(nHandle); +} + +//------------------------------------------------------------------------------ +staruno::Sequence<starbeans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const staruno::Sequence< ::rtl::OUString >& _rPropertyNames) throw(starbeans::UnknownPropertyException, staruno::RuntimeException) +{ + sal_Int32 nLen = _rPropertyNames.getLength(); + staruno::Sequence<starbeans::PropertyState> aRet(nLen); + starbeans::PropertyState* pValues = aRet.getArray(); + const ::rtl::OUString* pNames = _rPropertyNames.getConstArray(); + + cppu::IPropertyArrayHelper& rHelper = getInfoHelper(); + + staruno::Sequence<starbeans::Property> aProps = rHelper.getProperties(); + const starbeans::Property* pProps = aProps.getConstArray(); + sal_Int32 nPropCount = aProps.getLength(); + + osl::MutexGuard aGuard(rBHelper.rMutex); + for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps) + { + // get the values only for valid properties + if (pProps->Name.equals(*pNames)) + { + *pValues = getPropertyState(*pNames); + ++pValues; + ++pNames; + ++j; + } + } + + return aRet; +} + +//------------------------------------------------------------------------------ +starbeans::PropertyState OPropertyStateHelper::getPropertyStateByHandle(sal_Int32 nHandle) +{ + return starbeans::PropertyState_DIRECT_VALUE; +} + +//------------------------------------------------------------------------------ +void OPropertyStateHelper::setPropertyToDefaultByHandle(sal_Int32 nHandle) +{ +} + +//------------------------------------------------------------------------------ +staruno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 nHandle ) const +{ + return staruno::Any(); +} + +//......................................................................... +} +//......................................................................... + diff --git a/comphelper/source/streaming/basicio.cxx b/comphelper/source/streaming/basicio.cxx new file mode 100644 index 000000000000..56710f46b080 --- /dev/null +++ b/comphelper/source/streaming/basicio.cxx @@ -0,0 +1,208 @@ +/************************************************************************* + * + * $RCSfile: basicio.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_BASIC_IO_HXX_ +#include <comphelper/basicio.hxx> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << ( + const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, + const starawt::FontDescriptor& _rFont) +{ + _rxOutStream->writeUTF( _rFont.Name ); + _rxOutStream->writeShort( _rFont.Height ); + _rxOutStream->writeShort( _rFont.Width ); + _rxOutStream->writeUTF( _rFont.StyleName ); + _rxOutStream->writeShort( _rFont.Family ); + _rxOutStream->writeShort( _rFont.CharSet ); + _rxOutStream->writeShort( _rFont.Pitch ); + _rxOutStream->writeDouble( _rFont.CharacterWidth ); + _rxOutStream->writeDouble( _rFont.Weight ); + _rxOutStream->writeShort( _rFont.Slant ); + _rxOutStream->writeShort( _rFont.Underline ); + _rxOutStream->writeShort( _rFont.Strikeout ); + _rxOutStream->writeDouble( _rFont.Orientation ); + _rxOutStream->writeBoolean( _rFont.Kerning ); + _rxOutStream->writeBoolean( _rFont.WordLineMode ); + _rxOutStream->writeShort( _rFont.Type ); + return _rxOutStream; +} + +// FontDescriptor +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> ( + const staruno::Reference<stario::XObjectInputStream>& _rxInStream, + starawt::FontDescriptor& _rFont) +{ + // schreiben des Fontdescriptors + _rFont.Name = _rxInStream->readUTF(); + _rFont.Height = _rxInStream->readShort(); + _rFont.Width = _rxInStream->readShort(); + _rFont.StyleName = _rxInStream->readUTF(); + _rFont.Family = _rxInStream->readShort(); + _rFont.CharSet = _rxInStream->readShort(); + _rFont.Pitch = _rxInStream->readShort(); + _rFont.CharacterWidth = _rxInStream->readDouble(); + _rFont.Weight = _rxInStream->readDouble(); + _rFont.Slant = (starawt::FontSlant)_rxInStream->readShort(); + _rFont.Underline = _rxInStream->readShort(); + _rFont.Strikeout = _rxInStream->readShort(); + _rFont.Orientation = _rxInStream->readDouble(); + _rFont.Kerning = _rxInStream->readBoolean(); + _rFont.WordLineMode = _rxInStream->readBoolean(); + _rFont.Type = _rxInStream->readShort(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Bool& _rVal) +{ + _rVal = _rxInStream->readBoolean(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Bool _bVal) +{ + _rxOutStream->writeBoolean(_bVal); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, ::rtl::OUString& rStr) +{ + rStr = _rxInStream->readUTF(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const ::rtl::OUString& rStr) +{ + _rxOutStream->writeUTF(rStr); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int16& _rValue) +{ + _rValue = _rxInStream->readShort(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int16 _nValue) +{ + _rxOutStream->writeShort(_nValue); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt16& _rValue) +{ + _rValue = _rxInStream->readShort(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt16 _nValue) +{ + _rxOutStream->writeShort(_nValue); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt32& _rValue) +{ + _rValue = _rxInStream->readLong(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt32 _nValue) +{ + _rxOutStream->writeLong(_nValue); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int32& _rValue) +{ + _rValue = _rxInStream->readLong(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int32 _nValue) +{ + _rxOutStream->writeLong(_nValue); + return _rxOutStream; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + diff --git a/comphelper/source/streaming/makefile.mk b/comphelper/source/streaming/makefile.mk new file mode 100644 index 000000000000..891c4d5203fd --- /dev/null +++ b/comphelper/source/streaming/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=comphelper +TARGET=streaming + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/basicio.obj \ + $(SLO)$/oslfile2streamwrap.obj \ + $(SLO)$/seqstream.obj \ + $(SLO)$/streamsection.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/streaming/oslfile2streamwrap.cxx b/comphelper/source/streaming/oslfile2streamwrap.cxx new file mode 100644 index 000000000000..03f65286aba7 --- /dev/null +++ b/comphelper/source/streaming/oslfile2streamwrap.cxx @@ -0,0 +1,228 @@ +/************************************************************************* + * + * $RCSfile: oslfile2streamwrap.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ +#include <comphelper/oslfile2streamwrap.hxx> +#endif + +namespace comphelper +{ + using namespace osl; + +//------------------------------------------------------------------ +OSLInputStreamWrapper::OSLInputStreamWrapper( File& _rFile ) + :m_pFile(&_rFile) + ,m_bFileOwner(sal_False) +{ +} + +//------------------------------------------------------------------ +OSLInputStreamWrapper::OSLInputStreamWrapper( File* pStream, sal_Bool bOwner ) + :m_pFile( pStream ) + ,m_bFileOwner( bOwner ) +{ +} + +//------------------------------------------------------------------ +OSLInputStreamWrapper::~OSLInputStreamWrapper() +{ + if( m_bFileOwner ) + delete m_pFile; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) + throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + ::osl::MutexGuard aGuard( m_aMutex ); + + aData.realloc(nBytesToRead); + + sal_uInt64 nRead = 0; + FileBase::RC eError = m_pFile->read((void*)aData.getArray(), nBytesToRead, nRead); + if (eError != osl_File_E_None) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + // Wenn gelesene Zeichen < MaxLength, staruno::Sequence anpassen + if (nRead < (sal_uInt32)nBytesToRead) + aData.realloc( nRead ); + + return nRead; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nMaxBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + /* + if (m_pFile->IsEof()) + { + aData.realloc(0); + return 0; + } + else + */ + return readBytes(aData, nMaxBytesToRead); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OSLInputStreamWrapper::skipBytes(sal_Int32 nBytesToSkip) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nCurrentPos; + m_pFile->getPos(nCurrentPos); + + sal_uInt64 nNewPos = nCurrentPos + nBytesToSkip; + FileBase::RC eError = m_pFile->setPos(osl_Pos_Absolut, nNewPos); + if (eError != osl_File_E_None) + { + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + } + +#ifdef DBG_UTIL + m_pFile->getPos(nCurrentPos); + volatile int dummy = 0; // to take a look at last changes ;-) +#endif +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::available() throw( stario::NotConnectedException, staruno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nPos; + FileBase::RC eError = m_pFile->getPos(nPos); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nDummy = 0; + eError = m_pFile->setPos(Pos_End, nDummy); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nAvailable; + eError = m_pFile->getPos(nAvailable); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + nAvailable = nAvailable - nPos; + eError = m_pFile->setPos(Pos_Absolut, nPos); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + return nAvailable; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OSLInputStreamWrapper::closeInput() throw( stario::NotConnectedException, staruno::RuntimeException ) +{ + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + m_pFile->close(); + if (m_bFileOwner) + delete m_pFile; + + m_pFile = NULL; +} + +/*************************************************************************/ +// stario::XOutputStream +//------------------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + sal_uInt64 nWritten; + FileBase::RC eError = rFile.write(aData.getConstArray(),aData.getLength(), nWritten); + if (eError != osl_File_E_None || nWritten != aData.getLength()) + { + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + } +} + +//------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::flush() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ +} + +//------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::closeOutput() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + rFile.close(); +} + +} // namespace comphelper + + diff --git a/comphelper/source/streaming/seqstream.cxx b/comphelper/source/streaming/seqstream.cxx new file mode 100644 index 000000000000..469a9a963468 --- /dev/null +++ b/comphelper/source/streaming/seqstream.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: seqstream.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_SEQSTREAM_HXX +#include <comphelper/seqstream.hxx> +#endif + +#include <memory.h> // for memcpy + +namespace comphelper +{ + +//--------------------------------------------------------------------------------------------- +// class SequenceInputStream +//--------------------------------------------------------------------------------------------- + +//------------------------------------------------------------------ +SequenceInputStream::SequenceInputStream(const ByteSequence& rData) +: m_aData(rData) +, m_nPos(0) +{ +} + +// checks if closed, returns available size, not mutex-protected +//------------------------------------------------------------------ +inline sal_Int32 SequenceInputStream::avail() +{ + if (m_nPos == -1) + throw stario::NotConnectedException(::rtl::OUString(), *this); + + return m_aData.getLength() - m_nPos; +} + +// com::sun::star::io::XInputStream +//------------------------------------------------------------------ +sal_Int32 SAL_CALL SequenceInputStream::readBytes( staruno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, + stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + sal_Int32 nAvail = avail(); + + if (nBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),*this); + + if (nAvail < nBytesToRead) + nBytesToRead = nAvail; + + aData.realloc(nBytesToRead); + memcpy(aData.getArray(), m_aData.getConstArray() + m_nPos, nBytesToRead); + m_nPos += nBytesToRead; + + return nBytesToRead; +} + +//------------------------------------------------------------------ +sal_Int32 SAL_CALL SequenceInputStream::readSomeBytes( staruno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, + stario::IOException, staruno::RuntimeException) +{ + // all data is available at once + return readBytes(aData, nMaxBytesToRead); +} + +//------------------------------------------------------------------ +void SAL_CALL SequenceInputStream::skipBytes( sal_Int32 nBytesToSkip ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, + stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + sal_Int32 nAvail = avail(); + + if (nBytesToSkip < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),*this); + + if (nAvail < nBytesToSkip) + nBytesToSkip = nAvail; + + m_nPos += nBytesToSkip; +} + +//------------------------------------------------------------------ +sal_Int32 SAL_CALL SequenceInputStream::available( ) + throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return avail(); +} + +//------------------------------------------------------------------ +void SAL_CALL SequenceInputStream::closeInput( ) + throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException) +{ + if (m_nPos == -1) + throw stario::NotConnectedException(::rtl::OUString(), *this); + + m_nPos = -1; +} +} // namespace comphelper diff --git a/comphelper/source/streaming/streamsection.cxx b/comphelper/source/streaming/streamsection.cxx new file mode 100644 index 000000000000..3bd940849b4c --- /dev/null +++ b/comphelper/source/streaming/streamsection.cxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: streamsection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_STREAMSECTION_HXX_ +#include <comphelper/streamsection.hxx> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +namespace comphelper +{ + +//------------------------------------------------------------------------- +OStreamSection::OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput) + :m_xInStream(_rxInput) + ,m_xMarkStream(_rxInput, ::com::sun::star::uno::UNO_QUERY) + ,m_nBlockStart(-1) + ,m_nBlockLen(-1) +{ + OSL_ENSHURE(m_xInStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !"); + if (m_xInStream.is() && m_xMarkStream.is()) + { + m_nBlockLen = _rxInput->readLong(); + m_nBlockStart = m_xMarkStream->createMark(); + } +} + +//------------------------------------------------------------------------- +OStreamSection::OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength) + :m_xOutStream(_rxOutput) + ,m_xMarkStream(_rxOutput, ::com::sun::star::uno::UNO_QUERY) + ,m_nBlockStart(-1) + ,m_nBlockLen(-1) +{ + OSL_ENSHURE(m_xOutStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !"); + if (m_xOutStream.is() && m_xMarkStream.is()) + { + m_nBlockStart = m_xMarkStream->createMark(); + // a placeholder where we will write the overall length (within the destructor) + if (_nPresumedLength > 0) + m_nBlockLen = _nPresumedLength + sizeof(m_nBlockLen); + // as the caller did not consider - of course - the placeholder we are going to write + else + m_nBlockLen = 0; + m_xOutStream->writeLong(m_nBlockLen); + } +} + +//------------------------------------------------------------------------- +OStreamSection::~OStreamSection() +{ + try + { // don't allow any exceptions to leave this block, this may be called during the stack unwinding of an exception + // handling routing + if (m_xInStream.is() && m_xMarkStream.is()) + { // we're working on an input stream + m_xMarkStream->jumpToMark(m_nBlockStart); + m_xInStream->skipBytes(m_nBlockLen); + m_xMarkStream->deleteMark(m_nBlockStart); + } + else if (m_xOutStream.is() && m_xMarkStream.is()) + { + sal_Int32 nRealBlockLength = m_xMarkStream->offsetToMark(m_nBlockStart) - sizeof(m_nBlockLen); + if (m_nBlockLen && (m_nBlockLen == nRealBlockLength)) + // nothing to do : the estimation the caller gave us (in the ctor) was correct + m_xMarkStream->deleteMark(m_nBlockStart); + else + { // the estimation was wrong (or we didn't get one) + m_nBlockLen = nRealBlockLength; + m_xMarkStream->jumpToMark(m_nBlockStart); + m_xOutStream->writeLong(m_nBlockLen); + m_xMarkStream->jumpToFurthest(); + m_xMarkStream->deleteMark(m_nBlockStart); + } + } + } + catch(...) + { + } +} + +} // namespace comphelper + + diff --git a/comphelper/util/makefile.mk b/comphelper/util/makefile.mk new file mode 100644 index 000000000000..7e88cedcdb3e --- /dev/null +++ b/comphelper/util/makefile.mk @@ -0,0 +1,121 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=.. +PRJNAME=comphelper +TARGET=comphelper + +TARGETTYPE=CUI +USE_LDUMP2=TRUE + +ENABLE_EXCEPTIONS=TRUE + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +# --- Library ----------------------------------- + +LIB1FILES= $(SLB)$/container.lib \ + $(SLB)$/evtattmgr.lib \ + $(SLB)$/misc.lib \ + $(SLB)$/processfactory.lib \ + $(SLB)$/property.lib \ + $(SLB)$/streaming.lib + +LIB1TARGET=$(SLB)$/$(TARGET).lib + +SHL1TARGET=$(COMPHLP_TARGET)$(COMPHLP_MAJOR) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(OSLLIB) \ + $(SALLIB) \ + $(CPPRTLLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(SHL1TARGET) + +SHL1LIBS= $(LIB1TARGET) + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1DEPN= $(MISC)$/$(SHL1TARGET).flt \ + $(LIB1TARGET) + +DEFLIB1NAME=$(TARGET) + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +.IF "$(depend)"=="" + +# --- Goodies-Filter-Datei --- + +$(MISC)$/$(SHL1TARGET).flt: makefile.mk + @echo ------------------------------ + @echo CLEAR_THE_FILE > $@ + @echo __CT >>$@ +.ENDIF + diff --git a/comphelper/version.mk b/comphelper/version.mk new file mode 100644 index 000000000000..fec8833dea2a --- /dev/null +++ b/comphelper/version.mk @@ -0,0 +1,81 @@ +#************************************************************************* +# +# $RCSfile: version.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +# ----------------------------COMPHLP settings------------------------------------# +# target +COMPHLP_TARGET=comphelp + +# the major +COMPHLP_MAJOR=2 +# the minor +COMPHLP_MINOR=0 +# the micro +COMPHLP_MICRO=0 + +# this is a c++ compatible library +COMPHLP_CPP=1 + +COMPHLP=$(COMPHLP_TARGET_TARGET)_$(CMPEXT) + + + + |