LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ConfigurationControllerBroadcaster.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 2 100.0 %
Date: 2014-04-11 Functions: 5 5 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_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONCONTROLLERBROADCASTER_HXX
      21             : #define INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONCONTROLLERBROADCASTER_HXX
      22             : 
      23             : #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
      24             : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      25             : #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
      26             : 
      27             : #include <vector>
      28             : #include <boost/unordered_map.hpp>
      29             : 
      30             : namespace sd { namespace framework {
      31             : 
      32             : /** This class manages the set of XConfigurationChangeListeners and
      33             :     calls them when the ConfigurationController wants to broadcast an
      34             :     event.
      35             : 
      36             :     For every registered combination of listener and event type a user data
      37             :     object is stored.  This user data object is then given to the listener
      38             :     whenever it is called for an event.  With this the listener can use
      39             :     a switch statement to handle different event types.
      40             : */
      41          73 : class ConfigurationControllerBroadcaster
      42             : {
      43             : public:
      44             :     /** The given controller is used as origin of thrown exceptions.
      45             :     */
      46             :     ConfigurationControllerBroadcaster (
      47             :         const css::uno::Reference<
      48             :             css::drawing::framework::XConfigurationController>& rxController);
      49             : 
      50             :     /** Add a listener for one type of event.  When one listener is
      51             :         interested in more than one event type this method has to be called
      52             :         once for every event type.  Alternatively it can register as
      53             :         universal listener that will be called for all event types.
      54             :         @param rxListener
      55             :             A valid reference to a listener.
      56             :         @param rsEventType
      57             :             The type of event that the listener will be called for.  The
      58             :             empty string is a special value in that the listener will be
      59             :             called for all event types.
      60             :         @param rUserData
      61             :             This object is passed to the listener whenever it is called for
      62             :             the specified event type.  For different event types different
      63             :             user data objects can be provided.
      64             :         @throws IllegalArgumentException
      65             :             when an empty listener reference is given.
      66             :     */
      67             :     void AddListener(
      68             :         const css::uno::Reference<
      69             :             css::drawing::framework::XConfigurationChangeListener>& rxListener,
      70             :         const OUString& rsEventType,
      71             :         const css::uno::Any& rUserData);
      72             : 
      73             :     /** Remove all references to the given listener.  When one listener has
      74             :         been registered for more than one type of event then it is removed
      75             :         for all of them.
      76             :         @param rxListener
      77             :             A valid reference to a listener.
      78             :         @throws IllegalArgumentException
      79             :             when an empty listener reference is given.
      80             :     */
      81             :     void RemoveListener(
      82             :         const css::uno::Reference<
      83             :             css::drawing::framework::XConfigurationChangeListener>& rxListener);
      84             : 
      85             :     /** Broadcast the given event to all listeners that have been registered
      86             :         for its type of event as well as all universal listeners.
      87             : 
      88             :         When calling a listener results in a DisposedException being thrown
      89             :         the listener is unregistered automatically.
      90             :     */
      91             :     void NotifyListeners (
      92             :         const css::drawing::framework::ConfigurationChangeEvent& rEvent);
      93             : 
      94             :     /** This convenience variant of NotifyListeners create the event from
      95             :         the given arguments.
      96             :     */
      97             :     void NotifyListeners (
      98             :         const OUString& rsEventType,
      99             :         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
     100             :         const css::uno::Reference<css::drawing::framework::XResource>& rxResourceObject);
     101             : 
     102             :     /** Call all listeners and inform them that the
     103             :         ConfigurationController is being disposed.  When this method returns
     104             :         the list of registered listeners is empty.  Further calls to
     105             :         RemoveListener() are not necessary but do not result in an error.
     106             :     */
     107             :     void DisposeAndClear (void);
     108             : 
     109             : private:
     110             :     css::uno::Reference<
     111             :         com::sun::star::drawing::framework::XConfigurationController> mxConfigurationController;
     112       17580 :     class ListenerDescriptor {public:
     113             :         css::uno::Reference<
     114             :             css::drawing::framework::XConfigurationChangeListener> mxListener;
     115             :         css::uno::Any maUserData;
     116             :     };
     117             :     typedef ::std::vector<ListenerDescriptor> ListenerList;
     118             :     typedef ::boost::unordered_map
     119             :         <OUString,
     120             :          ListenerList,
     121             :          OUStringHash> ListenerMap;
     122             :     ListenerMap maListenerMap;
     123             : 
     124             :     /** Broadcast the given event to all listeners in the given list.
     125             : 
     126             :         When calling a listener results in a DisposedException being thrown
     127             :         the listener is unregistered automatically.
     128             :     */
     129             :     void NotifyListeners (
     130             :         const ListenerList& rList,
     131             :         const css::drawing::framework::ConfigurationChangeEvent& rEvent);
     132             : };
     133             : 
     134             : 
     135             : 
     136             : 
     137             : } } // end of namespace sd::framework
     138             : 
     139             : #endif
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10