ContextChangeEventMultiplexer.cxx (22de8995) ContextChangeEventMultiplexer.cxx (b9e67834)
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

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

31namespace framework {
32
33#define IMPLEMENTATION_NAME "org.apache.openoffice.comp.framework.ContextChangeEventMultiplexer"
34#define SERVICE_NAME "com.sun.star.ui.ContextChangeEventMultiplexer"
35#define SINGLETON_NAME "org.apache.openoffice.comp.framework.ContextChangeEventMultiplexerSigleton"
36
37
38ContextChangeEventMultiplexer::ContextChangeEventMultiplexer (
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

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

31namespace framework {
32
33#define IMPLEMENTATION_NAME "org.apache.openoffice.comp.framework.ContextChangeEventMultiplexer"
34#define SERVICE_NAME "com.sun.star.ui.ContextChangeEventMultiplexer"
35#define SINGLETON_NAME "org.apache.openoffice.comp.framework.ContextChangeEventMultiplexerSigleton"
36
37
38ContextChangeEventMultiplexer::ContextChangeEventMultiplexer (
39 const cssu::Reference<css::uno::XComponentContext>& rxContext)
39 const cssu::Reference<cssu::XComponentContext>& rxContext)
40 : ContextChangeEventMultiplexerInterfaceBase(m_aMutex),
41 maListeners()
42{
43 (void)rxContext;
44}
45
46
47
48
49ContextChangeEventMultiplexer::~ContextChangeEventMultiplexer (void)
50{
40 : ContextChangeEventMultiplexerInterfaceBase(m_aMutex),
41 maListeners()
42{
43 (void)rxContext;
44}
45
46
47
48
49ContextChangeEventMultiplexer::~ContextChangeEventMultiplexer (void)
50{
51 maListeners.clear();
52}
53
54
55
56
51}
52
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)));
62 for (ListenerMap::const_iterator iContainer(aListeners.begin()), iEnd(aListeners.end());
63 iContainer!=iEnd;
64 ++iContainer)
65 {
66 for (ListenerContainer::const_iterator
67 iListener(iContainer->second.begin()),
68 iContainerEnd(iContainer->second.end());
69 iListener!=iContainerEnd;
70 ++iListener)
71 {
72 (*iListener)->disposing(aEvent);
73 }
74 }
75}
76
77
78
79
57// XContextChangeEventMultiplexer
58
59void SAL_CALL ContextChangeEventMultiplexer::addContextChangeEventListener (
60 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener,
61 const cssu::Reference<cssu::XInterface>& rxEventFocus)
62 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
63{
64 if ( ! rxListener.is())

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

102 throw cssl::IllegalArgumentException(A2S("can not remove an empty reference"), static_cast<XWeak*>(this), 0);
103
104 ListenerMap::iterator iListenerContainer (maListeners.find(rxEventFocus));
105 if (iListenerContainer != maListeners.end())
106 {
107 ListenerContainer& rContainer (iListenerContainer->second);
108 const ListenerContainer::iterator iListener (::std::find(rContainer.begin(), rContainer.end(), rxListener));
109 if (iListener != rContainer.end())
80// XContextChangeEventMultiplexer
81
82void SAL_CALL ContextChangeEventMultiplexer::addContextChangeEventListener (
83 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener,
84 const cssu::Reference<cssu::XInterface>& rxEventFocus)
85 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
86{
87 if ( ! rxListener.is())

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

125 throw cssl::IllegalArgumentException(A2S("can not remove an empty reference"), static_cast<XWeak*>(this), 0);
126
127 ListenerMap::iterator iListenerContainer (maListeners.find(rxEventFocus));
128 if (iListenerContainer != maListeners.end())
129 {
130 ListenerContainer& rContainer (iListenerContainer->second);
131 const ListenerContainer::iterator iListener (::std::find(rContainer.begin(), rContainer.end(), rxListener));
132 if (iListener != rContainer.end())
133 {
110 rContainer.erase(iListener);
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())
140 maListeners.erase(iListenerContainer);
141 }
111 }
112
113}
114
115
116
117
118void SAL_CALL ContextChangeEventMultiplexer::removeAllContextChangeEventListeners (
119 const cssu::Reference<css::ui::XContextChangeEventListener>& rxListener)
120 throw(cssu::RuntimeException,cssl::IllegalArgumentException)
121{
122 if ( ! rxListener.is())
123 throw cssl::IllegalArgumentException(A2S("can not remove an empty reference"), static_cast<XWeak*>(this), 0);
124
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())
154 throw cssl::IllegalArgumentException(A2S("can not remove an empty reference"), static_cast<XWeak*>(this), 0);
155
156 ::std::vector<cssu::Reference<cssu::XInterface> > aContainersToRemove;
125 for (ListenerMap::iterator
126 iContainer(maListeners.begin()),
127 iEnd(maListeners.end());
128 iContainer!=iEnd;
129 ++iContainer)
130 {
131 const ListenerContainer::iterator iListener (::std::find(iContainer->second.begin(), iContainer->second.end(), rxListener));
132 if (iListener != iContainer->second.end())
157 for (ListenerMap::iterator
158 iContainer(maListeners.begin()),
159 iEnd(maListeners.end());
160 iContainer!=iEnd;
161 ++iContainer)
162 {
163 const ListenerContainer::iterator iListener (::std::find(iContainer->second.begin(), iContainer->second.end(), rxListener));
164 if (iListener != iContainer->second.end())
165 {
133 iContainer->second.erase(iListener);
166 iContainer->second.erase(iListener);
167
168 // When we just removed the last listener then mark the
169 // container as to be removed.
170 if (iContainer->second.empty())
171 aContainersToRemove.push_back(iContainer->first);
172 }
134 }
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 }
135}
136
137
138
139
140
141void SAL_CALL ContextChangeEventMultiplexer::broadcastContextChangeEvent (
142 const css::ui::ContextChangeEventObject& rEventObject,

--- 137 unchanged lines hidden ---
183}
184
185
186
187
188
189void SAL_CALL ContextChangeEventMultiplexer::broadcastContextChangeEvent (
190 const css::ui::ContextChangeEventObject& rEventObject,

--- 137 unchanged lines hidden ---