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 .
22 #include <com/sun/star/uno/Reference.hxx>
24 #include <unordered_map>
27 namespace com::sun::star::drawing::framework
{ class XConfigurationChangeListener
; }
28 namespace com::sun::star::drawing::framework
{ class XConfigurationController
; }
29 namespace com::sun::star::drawing::framework
{ class XResource
; }
30 namespace com::sun::star::drawing::framework
{ class XResourceId
; }
31 namespace com::sun::star::drawing::framework
{ struct ConfigurationChangeEvent
; }
33 namespace sd::framework
{
35 /** This class manages the set of XConfigurationChangeListeners and
36 calls them when the ConfigurationController wants to broadcast an
39 For every registered combination of listener and event type a user data
40 object is stored. This user data object is then given to the listener
41 whenever it is called for an event. With this the listener can use
42 a switch statement to handle different event types.
44 class ConfigurationControllerBroadcaster
47 /** The given controller is used as origin of thrown exceptions.
49 explicit ConfigurationControllerBroadcaster (
50 const css::uno::Reference
<
51 css::drawing::framework::XConfigurationController
>& rxController
);
53 /** Add a listener for one type of event. When one listener is
54 interested in more than one event type this method has to be called
55 once for every event type. Alternatively it can register as
56 universal listener that will be called for all event types.
58 A valid reference to a listener.
60 The type of event that the listener will be called for. The
61 empty string is a special value in that the listener will be
62 called for all event types.
64 This object is passed to the listener whenever it is called for
65 the specified event type. For different event types different
66 user data objects can be provided.
67 @throws IllegalArgumentException
68 when an empty listener reference is given.
71 const css::uno::Reference
<
72 css::drawing::framework::XConfigurationChangeListener
>& rxListener
,
73 const OUString
& rsEventType
,
74 const css::uno::Any
& rUserData
);
76 /** Remove all references to the given listener. When one listener has
77 been registered for more than one type of event then it is removed
80 A valid reference to a listener.
81 @throws IllegalArgumentException
82 when an empty listener reference is given.
85 const css::uno::Reference
<
86 css::drawing::framework::XConfigurationChangeListener
>& rxListener
);
88 /** Broadcast the given event to all listeners that have been registered
89 for its type of event as well as all universal listeners.
91 When calling a listener results in a DisposedException being thrown
92 the listener is unregistered automatically.
94 void NotifyListeners (
95 const css::drawing::framework::ConfigurationChangeEvent
& rEvent
);
97 /** This convenience variant of NotifyListeners create the event from
100 void NotifyListeners (
101 const OUString
& rsEventType
,
102 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxResourceId
,
103 const css::uno::Reference
<css::drawing::framework::XResource
>& rxResourceObject
);
105 /** Call all listeners and inform them that the
106 ConfigurationController is being disposed. When this method returns
107 the list of registered listeners is empty. Further calls to
108 RemoveListener() are not necessary but do not result in an error.
110 void DisposeAndClear();
113 css::uno::Reference
<css::drawing::framework::XConfigurationController
> mxConfigurationController
;
114 class ListenerDescriptor
117 css::uno::Reference
<css::drawing::framework::XConfigurationChangeListener
> mxListener
;
118 css::uno::Any maUserData
;
120 typedef std::vector
<ListenerDescriptor
> ListenerList
;
121 typedef std::unordered_map
123 ListenerList
> ListenerMap
;
124 ListenerMap maListenerMap
;
126 /** Broadcast the given event to all listeners in the given list.
128 When calling a listener results in a DisposedException being thrown
129 the listener is unregistered automatically.
131 void NotifyListeners (
132 const ListenerList
& rList
,
133 const css::drawing::framework::ConfigurationChangeEvent
& rEvent
);
136 } // end of namespace sd::framework
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */