lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / configmgr / source / broadcaster.cxx
blob06e502ade75bad86a4bce1b9a1e8ba726d54a2f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/config.h>
22 #include <cassert>
24 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
25 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
26 #include <com/sun/star/container/XContainerListener.hpp>
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
29 #include <com/sun/star/lang/XEventListener.hpp>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/uno/Exception.hpp>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/XInterface.hpp>
34 #include <com/sun/star/util/XChangesListener.hpp>
35 #include <cppuhelper/exc_hlp.hxx>
36 #include <rtl/string.h>
37 #include <rtl/ustrbuf.hxx>
38 #include <rtl/ustring.h>
39 #include <rtl/ustring.hxx>
41 #include "broadcaster.hxx"
43 namespace configmgr {
45 namespace {
47 void appendMessage(
48 OUStringBuffer & buffer, css::uno::Exception const & exception)
50 buffer.append("; ");
51 buffer.append(exception.Message);
56 void Broadcaster::addDisposeNotification(
57 css::uno::Reference< css::lang::XEventListener > const & listener,
58 css::lang::EventObject const & event)
60 disposeNotifications_.emplace_back(listener, event);
63 void Broadcaster::addContainerElementReplacedNotification(
64 css::uno::Reference< css::container::XContainerListener > const & listener,
65 css::container::ContainerEvent const & event)
67 containerElementReplacedNotifications_.emplace_back(listener, event);
70 void Broadcaster::addContainerElementInsertedNotification(
71 css::uno::Reference< css::container::XContainerListener > const & listener,
72 css::container::ContainerEvent const & event)
74 containerElementInsertedNotifications_.emplace_back(listener, event);
77 void Broadcaster::addContainerElementRemovedNotification(
78 css::uno::Reference< css::container::XContainerListener > const & listener,
79 css::container::ContainerEvent const & event)
81 containerElementRemovedNotifications_.emplace_back(listener, event);
84 void Broadcaster::addPropertyChangeNotification(
85 css::uno::Reference< css::beans::XPropertyChangeListener > const & listener,
86 css::beans::PropertyChangeEvent const & event)
88 propertyChangeNotifications_.emplace_back(listener, event);
91 void Broadcaster::addPropertiesChangeNotification(
92 css::uno::Reference< css::beans::XPropertiesChangeListener > const &
93 listener,
94 css::uno::Sequence< css::beans::PropertyChangeEvent > const & event)
96 propertiesChangeNotifications_.emplace_back(listener, event);
99 void Broadcaster::addChangesNotification(
100 css::uno::Reference< css::util::XChangesListener > const & listener,
101 css::util::ChangesEvent const & event)
103 changesNotifications_.emplace_back(listener, event);
106 void Broadcaster::send() {
107 css::uno::Any exception;
108 OUStringBuffer messages;
109 for (DisposeNotifications::iterator i(disposeNotifications_.begin());
110 i != disposeNotifications_.end(); ++i) {
111 try {
112 i->listener->disposing(i->event);
113 } catch (css::lang::DisposedException &) {
114 } catch (css::uno::Exception & e) {
115 exception = cppu::getCaughtException();
116 appendMessage(messages, e);
119 for (ContainerNotifications::iterator i(
120 containerElementInsertedNotifications_.begin());
121 i != containerElementInsertedNotifications_.end(); ++i)
123 try {
124 i->listener->elementInserted(i->event);
125 } catch (css::lang::DisposedException &) {
126 } catch (css::uno::Exception & e) {
127 exception = cppu::getCaughtException();
128 appendMessage(messages, e);
131 for (ContainerNotifications::iterator i(
132 containerElementRemovedNotifications_.begin());
133 i != containerElementRemovedNotifications_.end(); ++i)
135 try {
136 i->listener->elementRemoved(i->event);
137 } catch (css::lang::DisposedException &) {
138 } catch (css::uno::Exception & e) {
139 exception = cppu::getCaughtException();
140 appendMessage(messages, e);
143 for (ContainerNotifications::iterator i(
144 containerElementReplacedNotifications_.begin());
145 i != containerElementReplacedNotifications_.end(); ++i)
147 try {
148 i->listener->elementReplaced(i->event);
149 } catch (css::lang::DisposedException &) {
150 } catch (css::uno::Exception & e) {
151 exception = cppu::getCaughtException();
152 appendMessage(messages, e);
155 for (PropertyChangeNotifications::iterator i(
156 propertyChangeNotifications_.begin());
157 i != propertyChangeNotifications_.end(); ++i)
159 try {
160 i->listener->propertyChange(i->event);
161 } catch (css::lang::DisposedException &) {
162 } catch (css::uno::Exception & e) {
163 exception = cppu::getCaughtException();
164 appendMessage(messages, e);
167 for (PropertiesChangeNotifications::iterator i(
168 propertiesChangeNotifications_.begin());
169 i != propertiesChangeNotifications_.end(); ++i)
171 try {
172 i->listener->propertiesChange(i->event);
173 } catch (css::lang::DisposedException &) {
174 } catch (css::uno::Exception & e) {
175 exception = cppu::getCaughtException();
176 appendMessage(messages, e);
179 for (ChangesNotifications::iterator i(changesNotifications_.begin());
180 i != changesNotifications_.end(); ++i) {
181 try {
182 i->listener->changesOccurred(i->event);
183 } catch (css::lang::DisposedException &) {
184 } catch (css::uno::Exception & e) {
185 exception = cppu::getCaughtException();
186 appendMessage(messages, e);
189 if (exception.hasValue()) {
190 throw css::lang::WrappedTargetRuntimeException(
191 ("configmgr exceptions during listener notification" +
192 messages.makeStringAndClear()),
193 css::uno::Reference< css::uno::XInterface >(),
194 exception);
198 Broadcaster::DisposeNotification::DisposeNotification(
199 css::uno::Reference< css::lang::XEventListener > const & theListener,
200 css::lang::EventObject const & theEvent):
201 listener(theListener), event(theEvent)
203 assert(theListener.is());
206 Broadcaster::ContainerNotification::ContainerNotification(
207 css::uno::Reference< css::container::XContainerListener > const &
208 theListener,
209 css::container::ContainerEvent const & theEvent):
210 listener(theListener), event(theEvent)
212 assert(theListener.is());
215 Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
216 css::uno::Reference< css::beans::XPropertyChangeListener > const &
217 theListener,
218 css::beans::PropertyChangeEvent const & theEvent):
219 listener(theListener), event(theEvent)
221 assert(theListener.is());
224 Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
225 css::uno::Reference< css::beans::XPropertiesChangeListener > const &
226 theListener,
227 css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent):
228 listener(theListener), event(theEvent)
230 assert(theListener.is());
233 Broadcaster::ChangesNotification::ChangesNotification(
234 css::uno::Reference< css::util::XChangesListener > const & theListener,
235 css::util::ChangesEvent const & theEvent):
236 listener(theListener), event(theEvent)
238 assert(theListener.is());
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */