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