LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ConfigurationControllerBroadcaster.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 2 100.0 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SD_FRAMEWORK_CONFIGURATION_CONTROLLER_BROADCASTER_HXX
      30                 :            : #define SD_FRAMEWORK_CONFIGURATION_CONTROLLER_BROADCASTER_HXX
      31                 :            : 
      32                 :            : #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
      33                 :            : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      34                 :            : #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
      35                 :            : 
      36                 :            : #include <comphelper/stl_types.hxx>
      37                 :            : #include <vector>
      38                 :            : #include <boost/unordered_map.hpp>
      39                 :            : 
      40                 :            : namespace css = ::com::sun::star;
      41                 :            : 
      42                 :            : namespace sd { namespace framework {
      43                 :            : 
      44                 :            : /** This class manages the set of XConfigurationChangeListeners and
      45                 :            :     calls them when the ConfigurationController wants to broadcast an
      46                 :            :     event.
      47                 :            : 
      48                 :            :     For every registered combination of listener and event type a user data
      49                 :            :     object is stored.  This user data object is then given to the listener
      50                 :            :     whenever it is called for an event.  With this the listener can use
      51                 :            :     a switch statement to handle different event types.
      52                 :            : */
      53         [ +  - ]:        130 : class ConfigurationControllerBroadcaster
      54                 :            : {
      55                 :            : public:
      56                 :            :     /** The given controller is used as origin of thrown exceptions.
      57                 :            :     */
      58                 :            :     ConfigurationControllerBroadcaster (
      59                 :            :         const css::uno::Reference<
      60                 :            :             css::drawing::framework::XConfigurationController>& rxController);
      61                 :            : 
      62                 :            :     /** Add a listener for one type of event.  When one listener is
      63                 :            :         interested in more than one event type this method has to be called
      64                 :            :         once for every event type.  Alternatively it can register as
      65                 :            :         universal listener that will be called for all event types.
      66                 :            :         @param rxListener
      67                 :            :             A valid reference to a listener.
      68                 :            :         @param rsEventType
      69                 :            :             The type of event that the listener will be called for.  The
      70                 :            :             empty string is a special value in that the listener will be
      71                 :            :             called for all event types.
      72                 :            :         @param rUserData
      73                 :            :             This object is passed to the listener whenever it is called for
      74                 :            :             the specified event type.  For different event types different
      75                 :            :             user data objects can be provided.
      76                 :            :         @throws IllegalArgumentException
      77                 :            :             when an empty listener reference is given.
      78                 :            :     */
      79                 :            :     void AddListener(
      80                 :            :         const css::uno::Reference<
      81                 :            :             css::drawing::framework::XConfigurationChangeListener>& rxListener,
      82                 :            :         const ::rtl::OUString& rsEventType,
      83                 :            :         const css::uno::Any& rUserData);
      84                 :            : 
      85                 :            :     /** Remove all references to the given listener.  When one listener has
      86                 :            :         been registered for more than one type of event then it is removed
      87                 :            :         for all of them.
      88                 :            :         @param rxListener
      89                 :            :             A valid reference to a listener.
      90                 :            :         @throws IllegalArgumentException
      91                 :            :             when an empty listener reference is given.
      92                 :            :     */
      93                 :            :     void RemoveListener(
      94                 :            :         const css::uno::Reference<
      95                 :            :             css::drawing::framework::XConfigurationChangeListener>& rxListener);
      96                 :            : 
      97                 :            :     /** Broadcast the given event to all listeners that have been registered
      98                 :            :         for its type of event as well as all universal listeners.
      99                 :            : 
     100                 :            :         When calling a listener results in a DisposedException being thrown
     101                 :            :         the listener is unregistered automatically.
     102                 :            :     */
     103                 :            :     void NotifyListeners (
     104                 :            :         const css::drawing::framework::ConfigurationChangeEvent& rEvent);
     105                 :            : 
     106                 :            :     /** This convenience variant of NotifyListeners create the event from
     107                 :            :         the given arguments.
     108                 :            :     */
     109                 :            :     void NotifyListeners (
     110                 :            :         const ::rtl::OUString& rsEventType,
     111                 :            :         const ::css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
     112                 :            :         const ::css::uno::Reference<css::drawing::framework::XResource>& rxResourceObject);
     113                 :            : 
     114                 :            :     /** Call all listeners and inform them that the
     115                 :            :         ConfigurationController is being disposed.  When this method returns
     116                 :            :         the list of registered listeners is empty.  Further calls to
     117                 :            :         RemoveListener() are not necessary but do not result in an error.
     118                 :            :     */
     119                 :            :     void DisposeAndClear (void);
     120                 :            : 
     121                 :            : private:
     122                 :            :     css::uno::Reference<
     123                 :            :         com::sun::star::drawing::framework::XConfigurationController> mxConfigurationController;
     124                 :      31456 :     class ListenerDescriptor {public:
     125                 :            :         css::uno::Reference<
     126                 :            :             css::drawing::framework::XConfigurationChangeListener> mxListener;
     127                 :            :         css::uno::Any maUserData;
     128                 :            :     };
     129                 :            :     typedef ::std::vector<ListenerDescriptor> ListenerList;
     130                 :            :     typedef ::boost::unordered_map
     131                 :            :         <rtl::OUString,
     132                 :            :          ListenerList,
     133                 :            :          ::rtl::OUStringHash,
     134                 :            :          ::comphelper::UStringEqual> ListenerMap;
     135                 :            :     ListenerMap maListenerMap;
     136                 :            : 
     137                 :            :     /** Broadcast the given event to all listeners in the given list.
     138                 :            : 
     139                 :            :         When calling a listener results in a DisposedException being thrown
     140                 :            :         the listener is unregistered automatically.
     141                 :            :     */
     142                 :            :     void NotifyListeners (
     143                 :            :         const ListenerList& rList,
     144                 :            :         const css::drawing::framework::ConfigurationChangeEvent& rEvent);
     145                 :            : };
     146                 :            : 
     147                 :            : 
     148                 :            : 
     149                 :            : 
     150                 :            : } } // end of namespace sd::framework
     151                 :            : 
     152                 :            : #endif
     153                 :            : 
     154                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10