LCOV - code coverage report
Current view: top level - sfx2/source/inc - eventsupplier.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1 100.0 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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 _SFX_EVENTSUPPLIER_HXX_
      21                 :            : #define _SFX_EVENTSUPPLIER_HXX_
      22                 :            : 
      23                 :            : #include <com/sun/star/lang/XTypeProvider.hpp>
      24                 :            : #include <com/sun/star/container/XNameReplace.hpp>
      25                 :            : #include <com/sun/star/container/XSet.hpp>
      26                 :            : #include <com/sun/star/document/XEventListener.hpp>
      27                 :            : #include <com/sun/star/document/XEventBroadcaster.hpp>
      28                 :            : #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
      29                 :            : #include <com/sun/star/document/XDocumentEventListener.hpp>
      30                 :            : #include <com/sun/star/document/XEventsSupplier.hpp>
      31                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      32                 :            : #include <com/sun/star/task/XJobExecutor.hpp>
      33                 :            : #include <com/sun/star/uno/Reference.hxx>
      34                 :            : #include <com/sun/star/uno/Type.hxx>
      35                 :            : #include <sal/types.h>
      36                 :            : #include <osl/mutex.hxx>
      37                 :            : #include <cppuhelper/weak.hxx>
      38                 :            : #include <cppuhelper/implbase1.hxx>
      39                 :            : #include <cppuhelper/implbase2.hxx>
      40                 :            : #include <cppuhelper/implbase3.hxx>
      41                 :            : #include <cppuhelper/implbase4.hxx>
      42                 :            : #include <cppuhelper/implbase7.hxx>
      43                 :            : #include <comphelper/sequenceashashmap.hxx>
      44                 :            : #include <comphelper/sequenceasvector.hxx>
      45                 :            : #include <sfx2/sfxuno.hxx>
      46                 :            : 
      47                 :            : #include <cppuhelper/interfacecontainer.hxx>
      48                 :            : #include <svl/lstner.hxx>
      49                 :            : #include <unotools/eventcfg.hxx>
      50                 :            : 
      51                 :            : namespace comphelper
      52                 :            : {
      53                 :            :     class NamedValueCollection;
      54                 :            : }
      55                 :            : 
      56                 :            : //--------------------------------------------------------------------------------------------------------
      57                 :            : 
      58                 :            : #define NOSUCHELEMENTEXCEPTION      ::com::sun::star::container::NoSuchElementException
      59                 :            : #define XNAMEREPLACE                ::com::sun::star::container::XNameReplace
      60                 :            : #define DOCEVENTOBJECT              ::com::sun::star::document::EventObject
      61                 :            : #define XEVENTBROADCASTER           ::com::sun::star::document::XEventBroadcaster
      62                 :            : #define XDOCEVENTLISTENER           ::com::sun::star::document::XEventListener
      63                 :            : #define XEVENTSSUPPLIER             ::com::sun::star::document::XEventsSupplier
      64                 :            : #define EVENTOBJECT                 ::com::sun::star::lang::EventObject
      65                 :            : #define ILLEGALARGUMENTEXCEPTION    ::com::sun::star::lang::IllegalArgumentException
      66                 :            : #define WRAPPEDTARGETEXCEPTION      ::com::sun::star::lang::WrappedTargetException
      67                 :            : #define ANY                         ::com::sun::star::uno::Any
      68                 :            : #define REFERENCE                   ::com::sun::star::uno::Reference
      69                 :            : #define RUNTIMEEXCEPTION            ::com::sun::star::uno::RuntimeException
      70                 :            : #define SEQUENCE                    ::com::sun::star::uno::Sequence
      71                 :            : #define UNOTYPE                     ::com::sun::star::uno::Type
      72                 :            : #define OINTERFACECONTAINERHELPER   ::cppu::OInterfaceContainerHelper
      73                 :            : 
      74                 :            : //--------------------------------------------------------------------------------------------------------
      75                 :            : 
      76                 :            : class SfxObjectShell;
      77                 :            : class SvxMacro;
      78                 :            : 
      79                 :            : //--------------------------------------------------------------------------------------------------------
      80                 :            : 
      81                 :            : class SfxEvents_Impl : public ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameReplace, ::com::sun::star::document::XEventListener  >
      82                 :            : {
      83                 :            :     SEQUENCE< ::rtl::OUString >     maEventNames;
      84                 :            :     SEQUENCE< ANY >                 maEventData;
      85                 :            :     REFERENCE< XEVENTBROADCASTER >  mxBroadcaster;
      86                 :            :     ::osl::Mutex                    maMutex;
      87                 :            :     SfxObjectShell                 *mpObjShell;
      88                 :            : 
      89                 :            :     sal_Bool                    Warn_Impl( const String& );
      90                 :            : 
      91                 :            : public:
      92                 :            :                                 SfxEvents_Impl( SfxObjectShell* pShell,
      93                 :            :                                                 REFERENCE< XEVENTBROADCASTER > xBroadcaster );
      94                 :            :                                ~SfxEvents_Impl();
      95                 :            : 
      96                 :            :     //  --- XNameReplace ---
      97                 :            :     virtual void SAL_CALL       replaceByName( const ::rtl::OUString & aName, const ANY & aElement )
      98                 :            :                                     throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION,
      99                 :            :                                            WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION );
     100                 :            : 
     101                 :            :     //  --- XNameAccess ( parent of XNameReplace ) ---
     102                 :            :     virtual ANY SAL_CALL        getByName( const ::rtl::OUString& aName )
     103                 :            :                                     throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION,
     104                 :            :                                            RUNTIMEEXCEPTION );
     105                 :            :     virtual SEQUENCE< ::rtl::OUString > SAL_CALL getElementNames() throw ( RUNTIMEEXCEPTION );
     106                 :            :     virtual sal_Bool SAL_CALL   hasByName( const ::rtl::OUString& aName ) throw ( RUNTIMEEXCEPTION );
     107                 :            : 
     108                 :            :     //  --- XElementAccess ( parent of XNameAccess ) ---
     109                 :            :     virtual UNOTYPE SAL_CALL    getElementType() throw ( RUNTIMEEXCEPTION );
     110                 :            :     virtual sal_Bool SAL_CALL   hasElements() throw ( RUNTIMEEXCEPTION );
     111                 :            : 
     112                 :            :     // --- ::document::XEventListener ---
     113                 :            :     virtual void SAL_CALL       notifyEvent( const DOCEVENTOBJECT& aEvent )
     114                 :            :                                     throw( RUNTIMEEXCEPTION );
     115                 :            : 
     116                 :            :     // --- ::lang::XEventListener ---
     117                 :            :     virtual void SAL_CALL       disposing( const EVENTOBJECT& Source )
     118                 :            :                                     throw( RUNTIMEEXCEPTION );
     119                 :            : 
     120                 :            :     static SvxMacro*            ConvertToMacro( const ANY& rElement, SfxObjectShell* pDoc, sal_Bool bNormalizeMacro );
     121                 :            :     static void                 NormalizeMacro( const ANY& rIn, ANY& rOut, SfxObjectShell* pDoc );
     122                 :            :     static void                 NormalizeMacro(
     123                 :            :                                     const ::comphelper::NamedValueCollection& i_eventDescriptor,
     124                 :            :                                     ::comphelper::NamedValueCollection& o_normalizedDescriptor,
     125                 :            :                                     SfxObjectShell* i_document );
     126                 :            : };
     127                 :            : 
     128                 :            : //=============================================================================
     129                 :        433 : struct ModelCollectionMutexBase
     130                 :            : {
     131                 :            :     public:
     132                 :            :         ::osl::Mutex m_aLock;
     133                 :            : };
     134                 :            : 
     135                 :            : //=============================================================================
     136                 :            : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > > TModelList;
     137                 :            : 
     138                 :            : //=============================================================================
     139                 :            : class ModelCollectionEnumeration : public ModelCollectionMutexBase
     140                 :            :                                  , public ::cppu::WeakImplHelper1< ::com::sun::star::container::XEnumeration >
     141                 :            : {
     142                 :            : 
     143                 :            :     //-------------------------------------------------------------------------
     144                 :            :     // member
     145                 :            :     //-------------------------------------------------------------------------
     146                 :            :     private:
     147                 :            :         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR;
     148                 :            :         TModelList m_lModels;
     149                 :            :         TModelList::iterator m_pEnumerationIt;
     150                 :            : 
     151                 :            :     //-------------------------------------------------------------------------
     152                 :            :     // native interface
     153                 :            :     //-------------------------------------------------------------------------
     154                 :            :     public:
     155                 :            :         ModelCollectionEnumeration(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMGR);
     156                 :            :         virtual ~ModelCollectionEnumeration();
     157                 :            :         void setModelList(const TModelList& rList);
     158                 :            : 
     159                 :            :     //-------------------------------------------------------------------------
     160                 :            :     // uno interface
     161                 :            :     //-------------------------------------------------------------------------
     162                 :            :     public:
     163                 :            : 
     164                 :            :         // css.container.XEnumeration
     165                 :            :         virtual sal_Bool SAL_CALL hasMoreElements()
     166                 :            :             throw(::com::sun::star::uno::RuntimeException);
     167                 :            : 
     168                 :            :         virtual ::com::sun::star::uno::Any SAL_CALL nextElement()
     169                 :            :             throw(::com::sun::star::container::NoSuchElementException,
     170                 :            :                   ::com::sun::star::lang::WrappedTargetException     ,
     171                 :            :                   ::com::sun::star::uno::RuntimeException            );
     172                 :            : };
     173                 :            : 
     174                 :            : //=============================================================================
     175                 :            : class SfxGlobalEvents_Impl : public ModelCollectionMutexBase
     176                 :            :                            , public ::cppu::WeakImplHelper7< ::com::sun::star::lang::XServiceInfo
     177                 :            :                                                            , ::com::sun::star::document::XEventsSupplier
     178                 :            :                                                            , ::com::sun::star::document::XEventBroadcaster
     179                 :            :                                                            , ::com::sun::star::document::XDocumentEventBroadcaster
     180                 :            :                                                            , ::com::sun::star::document::XEventListener
     181                 :            :                                                            , ::com::sun::star::document::XDocumentEventListener
     182                 :            :                                                            , ::com::sun::star::container::XSet >
     183                 :            : {
     184                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR;
     185                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > m_xEvents;
     186                 :            :     ::com::sun::star::uno::WeakReference< ::com::sun::star::document::XEventListener > m_xJobExecutorListener;
     187                 :            :     OINTERFACECONTAINERHELPER m_aLegacyListeners;
     188                 :            :     OINTERFACECONTAINERHELPER m_aDocumentListeners;
     189                 :            :     TModelList m_lModels;
     190                 :            :     GlobalEventConfig* pImp;
     191                 :            : 
     192                 :            : public:
     193                 :            :     SfxGlobalEvents_Impl(const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& xSMGR);
     194                 :            :     virtual ~SfxGlobalEvents_Impl();
     195                 :            : 
     196                 :            :     SFX_DECL_XSERVICEINFO
     197                 :            : 
     198                 :            :     // css.document.XEventBroadcaster
     199                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents()
     200                 :            :         throw(::com::sun::star::uno::RuntimeException);
     201                 :            : 
     202                 :            :     virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener)
     203                 :            :         throw(::com::sun::star::uno::RuntimeException);
     204                 :            : 
     205                 :            :     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener)
     206                 :            :         throw(::com::sun::star::uno::RuntimeException);
     207                 :            : 
     208                 :            :     // css.document.XDocumentEventBroadcaster
     209                 :            :     virtual void SAL_CALL addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException);
     210                 :            :     virtual void SAL_CALL removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException);
     211                 :            :     virtual void SAL_CALL notifyDocumentEvent( const ::rtl::OUString& _EventName, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _ViewController, const ::com::sun::star::uno::Any& _Supplement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
     212                 :            : 
     213                 :            :     // css.document.XEventListener
     214                 :            :     virtual void SAL_CALL notifyEvent(const ::com::sun::star::document::EventObject& aEvent)
     215                 :            :         throw(::com::sun::star::uno::RuntimeException);
     216                 :            : 
     217                 :            :     // css.document.XDocumentEventListener
     218                 :            :     virtual void SAL_CALL documentEventOccured( const ::com::sun::star::document::DocumentEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
     219                 :            : 
     220                 :            :     // css.container.XSet
     221                 :            :     virtual sal_Bool SAL_CALL has(const ::com::sun::star::uno::Any& aElement)
     222                 :            :         throw(::com::sun::star::uno::RuntimeException);
     223                 :            : 
     224                 :            :     virtual void SAL_CALL insert(const ::com::sun::star::uno::Any& aElement)
     225                 :            :         throw(::com::sun::star::lang::IllegalArgumentException  ,
     226                 :            :               ::com::sun::star::container::ElementExistException,
     227                 :            :               ::com::sun::star::uno::RuntimeException           );
     228                 :            : 
     229                 :            :     virtual void SAL_CALL remove(const ::com::sun::star::uno::Any& aElement)
     230                 :            :         throw(::com::sun::star::lang::IllegalArgumentException   ,
     231                 :            :               ::com::sun::star::container::NoSuchElementException,
     232                 :            :               ::com::sun::star::uno::RuntimeException            );
     233                 :            : 
     234                 :            :     // css.container.XEnumerationAccess
     235                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration()
     236                 :            :         throw(::com::sun::star::uno::RuntimeException);
     237                 :            : 
     238                 :            :     // css.container.XElementAccess
     239                 :            :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
     240                 :            :         throw(::com::sun::star::uno::RuntimeException);
     241                 :            : 
     242                 :            :     virtual sal_Bool SAL_CALL hasElements()
     243                 :            :         throw(::com::sun::star::uno::RuntimeException);
     244                 :            : 
     245                 :            :     // css.lang.XEventListener
     246                 :            :     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& aEvent)
     247                 :            :         throw(::com::sun::star::uno::RuntimeException);
     248                 :            : 
     249                 :            : private:
     250                 :            : 
     251                 :            :     // threadsafe
     252                 :            :     void implts_notifyJobExecution(const ::com::sun::star::document::EventObject& aEvent);
     253                 :            :     void implts_checkAndExecuteEventBindings(const ::com::sun::star::document::DocumentEvent& aEvent);
     254                 :            :     void implts_notifyListener(const ::com::sun::star::document::DocumentEvent& aEvent);
     255                 :            : 
     256                 :            :     // not threadsafe
     257                 :            :     TModelList::iterator impl_searchDoc(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel);
     258                 :            : };
     259                 :            : 
     260                 :            : #endif
     261                 :            : 
     262                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10