1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SD_FRAMEWORK_CONFIGURATION_CONTROLLER_BROADCASTER_HXX 25 #define SD_FRAMEWORK_CONFIGURATION_CONTROLLER_BROADCASTER_HXX 26 27 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp> 28 #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 29 #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp> 30 31 #include <comphelper/stl_types.hxx> 32 #include <vector> 33 #include <hash_map> 34 35 namespace css = ::com::sun::star; 36 37 namespace sd { namespace framework { 38 39 /** This class manages the set of XConfigurationChangeListeners and 40 calls them when the ConfigurationController wants to broadcast an 41 event. 42 43 For every registered combination of listener and event type a user data 44 object is stored. This user data object is then given to the listener 45 whenever it is called for an event. With this the listener can use 46 a switch statement to handle different event types. 47 */ 48 class ConfigurationControllerBroadcaster 49 { 50 public: 51 /** The given controller is used as origin of thrown exceptions. 52 */ 53 ConfigurationControllerBroadcaster ( 54 const css::uno::Reference< 55 css::drawing::framework::XConfigurationController>& rxController); 56 57 /** Add a listener for one type of event. When one listener is 58 interested in more than one event type this method has to be called 59 once for every event type. Alternatively it can register as 60 universal listener that will be called for all event types. 61 @param rxListener 62 A valid reference to a listener. 63 @param rsEventType 64 The type of event that the listener will be called for. The 65 empty string is a special value in that the listener will be 66 called for all event types. 67 @param rUserData 68 This object is passed to the listener whenever it is called for 69 the specified event type. For different event types different 70 user data objects can be provided. 71 @throws IllegalArgumentException 72 when an empty listener reference is given. 73 */ 74 void AddListener( 75 const css::uno::Reference< 76 css::drawing::framework::XConfigurationChangeListener>& rxListener, 77 const ::rtl::OUString& rsEventType, 78 const css::uno::Any& rUserData); 79 80 /** Remove all references to the given listener. When one listener has 81 been registered for more than one type of event then it is removed 82 for all of them. 83 @param rxListener 84 A valid reference to a listener. 85 @throws IllegalArgumentException 86 when an empty listener reference is given. 87 */ 88 void RemoveListener( 89 const css::uno::Reference< 90 css::drawing::framework::XConfigurationChangeListener>& rxListener); 91 92 /** Broadcast the given event to all listeners that have been registered 93 for its type of event as well as all universal listeners. 94 95 When calling a listener results in a DisposedException being thrown 96 the listener is unregistered automatically. 97 */ 98 void NotifyListeners ( 99 const css::drawing::framework::ConfigurationChangeEvent& rEvent); 100 101 /** This convenience variant of NotifyListeners create the event from 102 the given arguments. 103 */ 104 void NotifyListeners ( 105 const ::rtl::OUString& rsEventType, 106 const ::css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId, 107 const ::css::uno::Reference<css::drawing::framework::XResource>& rxResourceObject); 108 109 /** Call all listeners and inform them that the 110 ConfigurationController is being disposed. When this method returns 111 the list of registered listeners is empty. Further calls to 112 RemoveListener() are not necessary but do not result in an error. 113 */ 114 void DisposeAndClear (void); 115 116 private: 117 css::uno::Reference< 118 com::sun::star::drawing::framework::XConfigurationController> mxConfigurationController; 119 class ListenerDescriptor {public: 120 css::uno::Reference< 121 css::drawing::framework::XConfigurationChangeListener> mxListener; 122 css::uno::Any maUserData; 123 }; 124 typedef ::std::vector<ListenerDescriptor> ListenerList; 125 typedef ::std::hash_map 126 <rtl::OUString, 127 ListenerList, 128 ::comphelper::UStringHash, 129 ::comphelper::UStringEqual> ListenerMap; 130 ListenerMap maListenerMap; 131 132 /** Broadcast the given event to all listeners in the given list. 133 134 When calling a listener results in a DisposedException being thrown 135 the listener is unregistered automatically. 136 */ 137 void NotifyListeners ( 138 const ListenerList& rList, 139 const css::drawing::framework::ConfigurationChangeEvent& rEvent); 140 }; 141 142 143 144 145 } } // end of namespace sd::framework 146 147 #endif 148