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