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