LCOV - code coverage report
Current view: top level - forms/source/inc - InterfaceContainer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 1 100.0 %
Date: 2015-06-13 12:38:46 Functions: 3 3 100.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 <comphelper/types.hxx>
      24             : #include <comphelper/uno3.hxx>
      25             : #include <com/sun/star/container/XNameReplace.hpp>
      26             : #include <com/sun/star/container/XIndexReplace.hpp>
      27             : #include <com/sun/star/container/XNameContainer.hpp>
      28             : #include <com/sun/star/lang/XEventListener.hpp>
      29             : #include <com/sun/star/lang/EventObject.hpp>
      30             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      31             : #include <com/sun/star/io/XPersistObject.hpp>
      32             : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
      33             : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
      34             : #include <com/sun/star/beans/XPropertySet.hpp>
      35             : #include <com/sun/star/script/XEventAttacherManager.hpp>
      36             : #include <com/sun/star/script/ScriptEvent.hpp>
      37             : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      38             : #include <com/sun/star/container/XContainer.hpp>
      39             : #include <com/sun/star/container/XIndexContainer.hpp>
      40             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      41             : #include <com/sun/star/form/XFormComponent.hpp>
      42             : #include <com/sun/star/util/XCloneable.hpp>
      43             : #include <osl/mutex.hxx>
      44             : #include <cppuhelper/interfacecontainer.hxx>
      45             : #include <cppuhelper/component.hxx>
      46             : #include <cppuhelper/implbase8.hxx>
      47             : #include <unordered_map>
      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& ) SAL_DELETED_FUNCTION;
      76             :         ElementDescription& operator=( const ElementDescription& ) SAL_DELETED_FUNCTION;
      77             :     };
      78             : 
      79             : typedef std::vector<InterfaceRef> OInterfaceArray;
      80             : typedef std::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) throw(css::uno::RuntimeException, std::exception);
     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             :     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             :                 bool _bEvents /* = sal_True */,
     219             :                 ElementDescription* _pApprovalResult /* = NULL */ ,
     220             :                 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 );
     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             : typedef ::cppu::ImplHelper1< ::com::sun::star::form::XFormComponent> OFormComponents_BASE;
     284             : typedef ::cppu::OComponentHelper FormComponentsBase;
     285             :     // else MSVC kills itself on some statements
     286             : class OFormComponents   :public FormComponentsBase
     287             :                         ,public OInterfaceContainer
     288             :                         ,public OFormComponents_BASE
     289             : {
     290             : protected:
     291             :     ::osl::Mutex                m_aMutex;
     292             :     ::comphelper::InterfaceRef  m_xParent;
     293             : 
     294             : public:
     295             :     OFormComponents(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rxFactory);
     296             :     OFormComponents( const OFormComponents& _cloneSource );
     297             :     virtual ~OFormComponents();
     298             : 
     299      175223 :     DECLARE_UNO3_AGG_DEFAULTS(OFormComponents, FormComponentsBase)
     300             : 
     301             :     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;
     302             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     303             : 
     304             : // OComponentHelper
     305             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
     306             : 
     307             : // ::com::sun::star::form::XFormComponent
     308             :     virtual ::comphelper::InterfaceRef SAL_CALL getParent() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     309             :     virtual void SAL_CALL setParent(const ::comphelper::InterfaceRef& Parent) throw(::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     310             : 
     311             :     // XEventListener
     312             :     using OInterfaceContainer::disposing;
     313             : };
     314             : 
     315             : }   // namespace frm
     316             : 
     317             : 
     318             : #endif // INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11