LCOV - code coverage report
Current view: top level - forms/source/inc - InterfaceContainer.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
      21             : #define INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
      22             : 
      23             : #include <boost/unordered_map.hpp>
      24             : #include <comphelper/types.hxx>
      25             : #include <comphelper/uno3.hxx>
      26             : #include <com/sun/star/container/XNameReplace.hpp>
      27             : #include <com/sun/star/container/XIndexReplace.hpp>
      28             : #include <com/sun/star/container/XNameContainer.hpp>
      29             : #include <com/sun/star/lang/XEventListener.hpp>
      30             : #include <com/sun/star/lang/EventObject.hpp>
      31             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      32             : #include <com/sun/star/io/XPersistObject.hpp>
      33             : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
      34             : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
      35             : #include <com/sun/star/beans/XPropertySet.hpp>
      36             : #include <com/sun/star/script/XEventAttacherManager.hpp>
      37             : #include <com/sun/star/script/ScriptEvent.hpp>
      38             : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      39             : #include <com/sun/star/container/XContainer.hpp>
      40             : #include <com/sun/star/container/XIndexContainer.hpp>
      41             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      42             : #include <com/sun/star/form/XFormComponent.hpp>
      43             : #include <com/sun/star/util/XCloneable.hpp>
      44             : #include <osl/mutex.hxx>
      45             : #include <cppuhelper/interfacecontainer.hxx>
      46             : #include <cppuhelper/component.hxx>
      47             : #include <cppuhelper/implbase8.hxx>
      48             : 
      49             : namespace com { namespace sun { namespace star { namespace uno {
      50             :     class XComponentContext;
      51             : } } } }
      52             : 
      53             : using namespace comphelper;
      54             : 
      55             : 
      56             : namespace frm
      57             : {
      58             : 
      59             : 
      60             : 
      61             : 
      62             :     struct ElementDescription
      63             :     {
      64             :     public:
      65             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >       xInterface;
      66             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >   xPropertySet;
      67             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild >     xChild;
      68             :         ::com::sun::star::uno::Any                                                  aElementTypeInterface;
      69             : 
      70             :     public:
      71             :         ElementDescription( );
      72             :         virtual ~ElementDescription();
      73             : 
      74             :     private:
      75             :         ElementDescription( const ElementDescription& );            // never implemented
      76             :         ElementDescription& operator=( const ElementDescription& ); // never implemented
      77             :     };
      78             : 
      79             : typedef ::std::vector<InterfaceRef> OInterfaceArray;
      80             : typedef ::boost::unordered_multimap< OUString, InterfaceRef, OUStringHash > OInterfaceMap;
      81             : 
      82             : 
      83             : // OInterfaceContainer
      84             : // implements a container for form components
      85             : 
      86             : typedef ::cppu::ImplHelper8 <   ::com::sun::star::container::XNameContainer
      87             :                             ,   ::com::sun::star::container::XIndexContainer
      88             :                             ,   ::com::sun::star::container::XContainer
      89             :                             ,   ::com::sun::star::container::XEnumerationAccess
      90             :                             ,   ::com::sun::star::script::XEventAttacherManager
      91             :                             ,   ::com::sun::star::beans::XPropertyChangeListener
      92             :                             ,   ::com::sun::star::io::XPersistObject
      93             :                             ,   ::com::sun::star::util::XCloneable
      94             :                             > OInterfaceContainer_BASE;
      95             : 
      96             : class OInterfaceContainer : public OInterfaceContainer_BASE
      97             : {
      98             : protected:
      99             :     ::osl::Mutex&                           m_rMutex;
     100             : 
     101             :     OInterfaceArray                         m_aItems;
     102             :     OInterfaceMap                           m_aMap;
     103             :     ::cppu::OInterfaceContainerHelper       m_aContainerListeners;
     104             : 
     105             :     const ::com::sun::star::uno::Type       m_aElementType;
     106             : 
     107             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>     m_xContext;
     108             : 
     109             : 
     110             :     // EventManager
     111             :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager>  m_xEventAttacher;
     112             : 
     113             : public:
     114             :     OInterfaceContainer(
     115             :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory,
     116             :         ::osl::Mutex& _rMutex,
     117             :         const ::com::sun::star::uno::Type& _rElementType);
     118             : 
     119             :     OInterfaceContainer( ::osl::Mutex& _rMutex, const OInterfaceContainer& _cloneSource );
     120             : 
     121             :     // late constructor for cloning
     122             :     void clonedFrom( const OInterfaceContainer& _cloneSource );
     123             : 
     124             : protected:
     125             :     virtual ~OInterfaceContainer();
     126             : 
     127             : public:
     128             : // ::com::sun::star::io::XPersistObject
     129             :     virtual OUString SAL_CALL getServiceName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE = 0;
     130             :     virtual void SAL_CALL write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     131             :     virtual void SAL_CALL read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     132             : 
     133             : // ::com::sun::star::lang::XEventListener
     134             :     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     135             : 
     136             : // ::com::sun::star::beans::XPropertyChangeListener
     137             :     virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     138             : 
     139             : // ::com::sun::star::container::XElementAccess
     140             :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
     141             :     virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     142             : 
     143             : // ::com::sun::star::container::XEnumerationAccess
     144             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration> SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     145             : 
     146             : // ::com::sun::star::container::XNameAccess
     147             :     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     148             :     virtual StringSequence SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     149             :     virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     150             : 
     151             : // ::com::sun::star::container::XNameReplace
     152             :     virtual void SAL_CALL replaceByName(const OUString& Name, const ::com::sun::star::uno::Any& _rElement) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     153             : 
     154             : // ::com::sun::star::container::XNameContainer
     155             :     virtual void SAL_CALL insertByName(const OUString& Name, const ::com::sun::star::uno::Any& _rElement) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     156             :     virtual void SAL_CALL removeByName(const OUString& Name) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     157             : 
     158             : // ::com::sun::star::container::XIndexAccess
     159             :     virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     160             :     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 _nIndex) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     161             : 
     162             : // ::com::sun::star::container::XIndexReplace
     163             :     virtual void SAL_CALL replaceByIndex(sal_Int32 _nIndex, const ::com::sun::star::uno::Any& _rElement) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     164             : 
     165             : // ::com::sun::star::container::XIndexContainer
     166             :     virtual void SAL_CALL insertByIndex(sal_Int32 _nIndex, const ::com::sun::star::uno::Any& Element) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     167             :     virtual void SAL_CALL removeByIndex(sal_Int32 _nIndex) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     168             : 
     169             : // ::com::sun::star::container::XContainer
     170             :     virtual void SAL_CALL addContainerListener(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     171             :     virtual void SAL_CALL removeContainerListener(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     172             : 
     173             : // ::com::sun::star::script::XEventAttacherManager
     174             :     virtual void SAL_CALL registerScriptEvent( sal_Int32 nIndex, const ::com::sun::star::script::ScriptEventDescriptor& aScriptEvent ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     175             :     virtual void SAL_CALL registerScriptEvents( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& aScriptEvents ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     176             :     virtual void SAL_CALL revokeScriptEvent( sal_Int32 nIndex, const OUString& aListenerType, const OUString& aEventMethod, const OUString& aRemoveListenerParam ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     177             :     virtual void SAL_CALL revokeScriptEvents( sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     178             :     virtual void SAL_CALL insertEntry( sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     179             :     virtual void SAL_CALL removeEntry( sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     180             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor > SAL_CALL getScriptEvents( sal_Int32 Index ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     181             :     virtual void SAL_CALL attach( sal_Int32 nIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xObject, const ::com::sun::star::uno::Any& aHelper ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ServiceNotRegisteredException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     182             :     virtual void SAL_CALL detach( sal_Int32 nIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xObject ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     183             :     virtual void SAL_CALL addScriptListener( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& xListener ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     184             :     virtual void SAL_CALL removeScriptListener( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& Listener ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     185             : 
     186             : protected:
     187             :     // helper
     188             :     virtual void SAL_CALL disposing();
     189             :     virtual void removeElementsNoEvents(sal_Int32 nIndex);
     190             : 
     191             :     /** to be overridden if elements which are to be inserted into the container shall be checked
     192             : 
     193             :         <p>the ElementDescription given can be used to cache information about the object - it will be passed
     194             :         later on to implInserted/implReplaced.</p>
     195             :     */
     196             :     virtual void approveNewElement(
     197             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject,
     198             :                     ElementDescription* _pElement
     199             :                 );
     200             : 
     201             :     virtual ElementDescription* createElementMetaData( );
     202             : 
     203             :     /** inserts an object into our internal structures
     204             : 
     205             :         @param _nIndex
     206             :             the index at which position it should be inserted
     207             :         @param _bEvents
     208             :             if <TRUE/>, event knittings will be done
     209             :         @param _pApprovalResult
     210             :             must contain the result of an approveNewElement call. Can be <NULL/>, in this case, the approval
     211             :             is done within implInsert.
     212             :         @param _bFire
     213             :             if <TRUE/>, a notification about the insertion will be fired
     214             :     */
     215             :             void implInsert(
     216             :                 sal_Int32 _nIndex,
     217             :                 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject,
     218             :                 sal_Bool _bEvents /* = sal_True */,
     219             :                 ElementDescription* _pApprovalResult /* = NULL */ ,
     220             :                 sal_Bool _bFire /* = sal_True */
     221             :             ) throw(::com::sun::star::lang::IllegalArgumentException);
     222             : 
     223             :     // called after the object is inserted, but before the "real listeners" are notified
     224             :     virtual void implInserted( const ElementDescription* _pElement );
     225             :     // called after the object is removed, but before the "real listeners" are notified
     226             :     virtual void implRemoved(const InterfaceRef& _rxObject);
     227             : 
     228             :     /** called after an object was replaced. The default implementation notifies our listeners, after releasing
     229             :         the instance lock.
     230             :     */
     231             :     virtual void impl_replacedElement(
     232             :                     const ::com::sun::star::container::ContainerEvent& _rEvent,
     233             :                     ::osl::ClearableMutexGuard& _rInstanceLock
     234             :                 );
     235             : 
     236             :     void SAL_CALL writeEvents(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
     237             :     void SAL_CALL readEvents(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
     238             : 
     239             :     /** replace an element, specified by position
     240             : 
     241             :         @precond <arg>_nIndex</arg> is a valid index
     242             :         @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
     243             : 
     244             :     */
     245             :     void implReplaceByIndex(
     246             :             const sal_Int32 _nIndex,
     247             :             const ::com::sun::star::uno::Any& _rNewElement,
     248             :             ::osl::ClearableMutexGuard& _rClearBeforeNotify
     249             :         );
     250             : 
     251             :     /** removes an element, specified by position
     252             : 
     253             :         @precond <arg>_nIndex</arg> is a valid index
     254             :         @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
     255             : 
     256             :     */
     257             :     void implRemoveByIndex(
     258             :             const sal_Int32 _nIndex,
     259             :             ::osl::ClearableMutexGuard& _rClearBeforeNotify
     260             :         );
     261             : 
     262             :     /** validates the given index
     263             :         @throws ::com::sun::star::lang::IndexOutOfBoundsException
     264             :             if the given index does not denote a valid position in our children array
     265             :     */
     266             :     void implCheckIndex( const sal_Int32 _nIndex ) SAL_THROW( ( ::com::sun::star::lang::IndexOutOfBoundsException ) );
     267             : 
     268             : private:
     269             :     // hack for Vba Events
     270             :     void impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIndex );
     271             : 
     272             :     // the runtime event format has changed from version SO5.2 to OOo
     273             :     enum EventFormat
     274             :     {
     275             :         efVersionSO5x,
     276             :         efVersionSO6x
     277             :     };
     278             :     void    transformEvents( const EventFormat _eTargetFormat );
     279             : 
     280             :     void    impl_createEventAttacher_nothrow();
     281             : };
     282             : 
     283             : 
     284             : //= OFormComponents
     285             : 
     286             : typedef ::cppu::ImplHelper1< ::com::sun::star::form::XFormComponent> OFormComponents_BASE;
     287             : typedef ::cppu::OComponentHelper FormComponentsBase;
     288             :     // else MSVC kills itself on some statements
     289             : class OFormComponents   :public FormComponentsBase
     290             :                         ,public OInterfaceContainer
     291             :                         ,public OFormComponents_BASE
     292             : {
     293             : protected:
     294             :     ::osl::Mutex                m_aMutex;
     295             :     ::comphelper::InterfaceRef  m_xParent;
     296             : 
     297             : public:
     298             :     OFormComponents(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory);
     299             :     OFormComponents( const OFormComponents& _cloneSource );
     300             :     virtual ~OFormComponents();
     301             : 
     302           0 :     DECLARE_UNO3_AGG_DEFAULTS(OFormComponents, FormComponentsBase)
     303             : 
     304             :     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     305             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     306             : 
     307             : // OComponentHelper
     308             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     309             : 
     310             : // ::com::sun::star::form::XFormComponent
     311             :     virtual ::comphelper::InterfaceRef SAL_CALL getParent() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     312             :     virtual void SAL_CALL setParent(const ::comphelper::InterfaceRef& Parent) throw(::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     313             : 
     314             :     // XEventListener
     315             :     using OInterfaceContainer::disposing;
     316             : };
     317             : 
     318             : }   // namespace frm
     319             : 
     320             : 
     321             : #endif // INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10