ContextChangeEventMultiplexer.cxx (b9e67834) ContextChangeEventMultiplexer.cxx (95a18594)
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

--- 44 unchanged lines hidden (view full) ---

53
54
55
56void SAL_CALL ContextChangeEventMultiplexer::disposing (void)
57{
58 ListenerMap aListeners;
59 aListeners.swap(maListeners);
60
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

--- 44 unchanged lines hidden (view full) ---

53
54
55
56void SAL_CALL ContextChangeEventMultiplexer::disposing (void)
57{
58 ListenerMap aListeners;
59 aListeners.swap(maListeners);
60
61 css::lang::EventObject aEvent (cssu::Reference<cssu::XInterface>(static_cast<XWeak*>(this)));
61 cssu::Reference<cssu::XInterface> xThis (static_cast<XWeak*>(this));
62 css::lang::EventObject aEvent (xThis);
62 for (ListenerMap::const_iterator iContainer(aListeners.begin()), iEnd(aListeners.end());
63 iContainer!=iEnd;
64 ++iContainer)
65 {
66 for (ListenerContainer::const_iterator
63 for (ListenerMap::const_iterator iContainer(aListeners.begin()), iEnd(aListeners.end());
64 iContainer!=iEnd;
65 ++iContainer)
66 {
67 for (ListenerContainer::const_iterator
67 iListener(iContainer->second.begin()),
68 iContainerEnd(iContainer->second.end());
68 iListener(iContainer->second.maListeners.begin()),
69 iContainerEnd(iContainer->second.maListeners.end());
69 iListener!=iContainerEnd;
70 ++iListener)
71 {
72 (*iListener)->disposing(aEvent);
73 }
74 }
75}
76

--- 8 unchanged lines hidden (view full) ---

85 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
86{
87 if ( ! rxListener.is())
88 throw css::lang::IllegalArgumentException(
89 A2S("can not add an empty reference"),
90 static_cast<XWeak*>(this),
91 0);
92
70 iListener!=iContainerEnd;
71 ++iListener)
72 {
73 (*iListener)->disposing(aEvent);
74 }
75 }
76}
77

--- 8 unchanged lines hidden (view full) ---

86 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
87{
88 if ( ! rxListener.is())
89 throw css::lang::IllegalArgumentException(
90 A2S("can not add an empty reference"),
91 static_cast<XWeak*>(this),
92 0);
93
93 ListenerMap::iterator iListenerContainer (maListeners.find(rxEventFocus));
94 if (iListenerContainer == maListeners.end())
94 ListenerMap::iterator iDescriptor (maListeners.find(rxEventFocus));
95 if (iDescriptor == maListeners.end())
95 {
96 // Create a new listener container for the event focus.
96 {
97 // Create a new listener container for the event focus.
97 iListenerContainer = maListeners.insert(
98 iDescriptor = maListeners.insert(
98 ListenerMap::value_type(
99 rxEventFocus,
99 ListenerMap::value_type(
100 rxEventFocus,
100 ListenerContainer())).first;
101 FocusDescriptor())).first;
101 }
102 }
102 if (iListenerContainer != maListeners.end())
103 if (iDescriptor != maListeners.end())
103 {
104 {
104 ListenerContainer& rContainer (iListenerContainer->second);
105 ListenerContainer& rContainer (iDescriptor->second.maListeners);
105 if (::std::find(rContainer.begin(), rContainer.end(), rxListener) == rContainer.end())
106 rContainer.push_back(rxListener);
107 else
108 {
109 // The listener was added for the same event focus
110 // previously. That is an error.
111 throw cssl::IllegalArgumentException(A2S("listener added twice"), static_cast<XWeak*>(this), 0);
112 }
113 }
106 if (::std::find(rContainer.begin(), rContainer.end(), rxListener) == rContainer.end())
107 rContainer.push_back(rxListener);
108 else
109 {
110 // The listener was added for the same event focus
111 // previously. That is an error.
112 throw cssl::IllegalArgumentException(A2S("listener added twice"), static_cast<XWeak*>(this), 0);
113 }
114 }
115
116 // Send out an initial event that informs the new listener about
117 // the current context.
118 if (rxEventFocus.is() && iDescriptor != maListeners.end())
119 {
120 css::ui::ContextChangeEventObject aEvent (
121 NULL,
122 iDescriptor->second.msCurrentApplicationName,
123 iDescriptor->second.msCurrentContextName);
124 rxListener->notifyContextChangeEvent(aEvent);
125 }
114}
115
116
117
118
119void SAL_CALL ContextChangeEventMultiplexer::removeContextChangeEventListener (
120 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener,
121 const cssu::Reference<cssu::XInterface>& rxEventFocus)
122 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
123{
124 if ( ! rxListener.is())
126}
127
128
129
130
131void SAL_CALL ContextChangeEventMultiplexer::removeContextChangeEventListener (
132 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener,
133 const cssu::Reference<cssu::XInterface>& rxEventFocus)
134 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
135{
136 if ( ! rxListener.is())
125 throw cssl::IllegalArgumentException(A2S("can not remove an empty reference"), static_cast<XWeak*>(this), 0);
137 throw cssl::IllegalArgumentException(
138 A2S("can not remove an empty reference"),
139 static_cast<XWeak*>(this), 0);
126
140
127 ListenerMap::iterator iListenerContainer (maListeners.find(rxEventFocus));
128 if (iListenerContainer != maListeners.end())
141 ListenerMap::iterator iDescriptor (maListeners.find(rxEventFocus));
142 if (iDescriptor != maListeners.end())
129 {
143 {
130 ListenerContainer& rContainer (iListenerContainer->second);
131 const ListenerContainer::iterator iListener (::std::find(rContainer.begin(), rContainer.end(), rxListener));
144 ListenerContainer& rContainer (iDescriptor->second.maListeners);
145 const ListenerContainer::iterator iListener (
146 ::std::find(rContainer.begin(), rContainer.end(), rxListener));
132 if (iListener != rContainer.end())
133 {
134 rContainer.erase(iListener);
135
136 // Remove the listener container as well when its last
137 // listener was just removed. This prevents us from
138 // holding the focus alive.
139 if (rContainer.empty())
147 if (iListener != rContainer.end())
148 {
149 rContainer.erase(iListener);
150
151 // Remove the listener container as well when its last
152 // listener was just removed. This prevents us from
153 // holding the focus alive.
154 if (rContainer.empty())
140 maListeners.erase(iListenerContainer);
155 maListeners.erase(iDescriptor);
141 }
142 }
143
144}
145
146
147
148
149void SAL_CALL ContextChangeEventMultiplexer::removeAllContextChangeEventListeners (
150 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener)
151 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
152{
153 if ( ! rxListener.is())
156 }
157 }
158
159}
160
161
162
163
164void SAL_CALL ContextChangeEventMultiplexer::removeAllContextChangeEventListeners (
165 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener)
166 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
167{
168 if ( ! rxListener.is())
154 throw cssl::IllegalArgumentException(A2S("can not remove an empty reference"), static_cast<XWeak*>(this), 0);
169 throw cssl::IllegalArgumentException(
170 A2S("can not remove an empty reference"),
171 static_cast<XWeak*>(this), 0);
155
156 ::std::vector<cssu::Reference<cssu::XInterface> > aContainersToRemove;
157 for (ListenerMap::iterator
158 iContainer(maListeners.begin()),
159 iEnd(maListeners.end());
160 iContainer!=iEnd;
161 ++iContainer)
162 {
172
173 ::std::vector<cssu::Reference<cssu::XInterface> > aContainersToRemove;
174 for (ListenerMap::iterator
175 iContainer(maListeners.begin()),
176 iEnd(maListeners.end());
177 iContainer!=iEnd;
178 ++iContainer)
179 {
163 const ListenerContainer::iterator iListener (::std::find(iContainer->second.begin(), iContainer->second.end(), rxListener));
164 if (iListener != iContainer->second.end())
180 const ListenerContainer::iterator iListener (
181 ::std::find(iContainer->second.maListeners.begin(), iContainer->second.maListeners.end(), rxListener));
182 if (iListener != iContainer->second.maListeners.end())
165 {
183 {
166 iContainer->second.erase(iListener);
184 iContainer->second.maListeners.erase(iListener);
167
168 // When we just removed the last listener then mark the
169 // container as to be removed.
185
186 // When we just removed the last listener then mark the
187 // container as to be removed.
170 if (iContainer->second.empty())
188 if (iContainer->second.maListeners.empty())
171 aContainersToRemove.push_back(iContainer->first);
172 }
173 }
174
175 for (::std::vector<cssu::Reference<cssu::XInterface> >::iterator
176 iFocus(aContainersToRemove.begin()),
177 iEnd(aContainersToRemove.end());
178 iFocus!=iEnd;
179 ++iFocus)
180 {
181 maListeners.erase(*iFocus);
182 }
183}
184
185
186
187
189 aContainersToRemove.push_back(iContainer->first);
190 }
191 }
192
193 for (::std::vector<cssu::Reference<cssu::XInterface> >::iterator
194 iFocus(aContainersToRemove.begin()),
195 iEnd(aContainersToRemove.end());
196 iFocus!=iEnd;
197 ++iFocus)
198 {
199 maListeners.erase(*iFocus);
200 }
201}
202
203
204
205
188
189void SAL_CALL ContextChangeEventMultiplexer::broadcastContextChangeEvent (
190 const css::ui::ContextChangeEventObject& rEventObject,
191 const cssu::Reference<cssu::XInterface>& rxEventFocus)
192 throw(cssu::RuntimeException)
193{
206void SAL_CALL ContextChangeEventMultiplexer::broadcastContextChangeEvent (
207 const css::ui::ContextChangeEventObject& rEventObject,
208 const cssu::Reference<cssu::XInterface>& rxEventFocus)
209 throw(cssu::RuntimeException)
210{
211 // Remember the current context.
212 if (rxEventFocus.is())
213 {
214 ListenerMap::iterator iDescriptor (maListeners.find(rxEventFocus));
215 if (iDescriptor != maListeners.end())
216 {
217 iDescriptor->second.msCurrentApplicationName = rEventObject.ApplicationName;
218 iDescriptor->second.msCurrentContextName = rEventObject.ContextName;
219 }
220 }
221
194 BroadcastEventToSingleContainer(rEventObject, rxEventFocus);
195 if (rxEventFocus.is())
196 BroadcastEventToSingleContainer(rEventObject, NULL);
197}
198
199
200
201
202void ContextChangeEventMultiplexer::BroadcastEventToSingleContainer (
203 const css::ui::ContextChangeEventObject& rEventObject,
204 const cssu::Reference<cssu::XInterface>& rxEventFocus)
205{
222 BroadcastEventToSingleContainer(rEventObject, rxEventFocus);
223 if (rxEventFocus.is())
224 BroadcastEventToSingleContainer(rEventObject, NULL);
225}
226
227
228
229
230void ContextChangeEventMultiplexer::BroadcastEventToSingleContainer (
231 const css::ui::ContextChangeEventObject& rEventObject,
232 const cssu::Reference<cssu::XInterface>& rxEventFocus)
233{
206 ListenerMap::iterator iListenerContainer (maListeners.find(rxEventFocus));
207 if (iListenerContainer != maListeners.end())
234 ListenerMap::iterator iDescriptor (maListeners.find(rxEventFocus));
235 if (iDescriptor != maListeners.end())
208 {
209 // Create a copy of the listener container to avoid problems
210 // when one of the called listeners calls add... or remove...
236 {
237 // Create a copy of the listener container to avoid problems
238 // when one of the called listeners calls add... or remove...
211 ListenerContainer aContainer (iListenerContainer->second);
239 ListenerContainer aContainer (iDescriptor->second.maListeners);
212 for (ListenerContainer::const_iterator
213 iListener(aContainer.begin()),
214 iEnd(aContainer.end());
215 iListener!=iEnd;
216 ++iListener)
217 {
218 (*iListener)->notifyContextChangeEvent(rEventObject);
219 }

--- 108 unchanged lines hidden ---
240 for (ListenerContainer::const_iterator
241 iListener(aContainer.begin()),
242 iEnd(aContainer.end());
243 iListener!=iEnd;
244 ++iListener)
245 {
246 (*iListener)->notifyContextChangeEvent(rEventObject);
247 }

--- 108 unchanged lines hidden ---