1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONCONTROLLERBROADCASTER_HXX
21 #define INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONCONTROLLERBROADCASTER_HXX
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>
27 #include <unordered_map>
30 namespace sd
{ namespace framework
{
32 /** This class manages the set of XConfigurationChangeListeners and
33 calls them when the ConfigurationController wants to broadcast an
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.
41 class ConfigurationControllerBroadcaster
44 /** The given controller is used as origin of thrown exceptions.
46 ConfigurationControllerBroadcaster (
47 const css::uno::Reference
<
48 css::drawing::framework::XConfigurationController
>& rxController
);
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.
55 A valid reference to a listener.
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.
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.
68 const css::uno::Reference
<
69 css::drawing::framework::XConfigurationChangeListener
>& rxListener
,
70 const OUString
& rsEventType
,
71 const css::uno::Any
& rUserData
);
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
77 A valid reference to a listener.
78 @throws IllegalArgumentException
79 when an empty listener reference is given.
82 const css::uno::Reference
<
83 css::drawing::framework::XConfigurationChangeListener
>& rxListener
);
85 /** Broadcast the given event to all listeners that have been registered
86 for its type of event as well as all universal listeners.
88 When calling a listener results in a DisposedException being thrown
89 the listener is unregistered automatically.
91 void NotifyListeners (
92 const css::drawing::framework::ConfigurationChangeEvent
& rEvent
);
94 /** This convenience variant of NotifyListeners create the event from
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
);
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.
107 void DisposeAndClear();
111 com::sun::star::drawing::framework::XConfigurationController
> mxConfigurationController
;
112 class ListenerDescriptor
{public:
114 css::drawing::framework::XConfigurationChangeListener
> mxListener
;
115 css::uno::Any maUserData
;
117 typedef std::vector
<ListenerDescriptor
> ListenerList
;
118 typedef std::unordered_map
121 OUStringHash
> ListenerMap
;
122 ListenerMap maListenerMap
;
124 /** Broadcast the given event to all listeners in the given list.
126 When calling a listener results in a DisposedException being thrown
127 the listener is unregistered automatically.
129 void NotifyListeners (
130 const ListenerList
& rList
,
131 const css::drawing::framework::ConfigurationChangeEvent
& rEvent
);
134 } } // end of namespace sd::framework
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */