update dev300-m58
[ooovba.git] / configmgr / source / api2 / confignotifier.cxx
blob59413e0f4c577e7a440442fe6fccaa48af927fd5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: confignotifier.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "confignotifier.hxx"
36 #include "notifierimpl.hxx"
37 #include "broadcaster.hxx"
39 #include "noderef.hxx"
40 #include "valueref.hxx"
41 #include "nodechange.hxx"
43 #include "apinodeaccess.hxx"
44 #include "apitreeaccess.hxx"
45 #include "apitreeimplobj.hxx"
47 #include <set>
48 #include <functional>
50 namespace configmgr
52 namespace configapi
54 // ---------------------------------------------------------------------------------------------------
55 // class Notifier (-Impl)
56 // ---------------------------------------------------------------------------------------------------
58 Notifier::Notifier(vos::ORef<NotifierImpl> const& aImpl,ApiTreeImpl const* pTree)
59 : m_aImpl(aImpl)
60 , m_pTree(pTree)
62 OSL_ENSURE(aImpl.isValid(),"Invalid initialization of a Notifier: No impl");
63 OSL_ENSURE(pTree,"Invalid initialization of a Notifier: No tree");
65 // ---------------------------------------------------------------------------------------------------
67 Notifier::Notifier(Notifier const& aOther)
68 : m_aImpl(aOther.m_aImpl)
69 , m_pTree(aOther.m_pTree)
72 // ---------------------------------------------------------------------------------------------------
74 Notifier::~Notifier()
77 // ---------------------------------------------------------------------------------------------------
79 Broadcaster Notifier::makeBroadcaster(configuration::NodeChange const& aChange, bool bLocal) const
81 return Broadcaster(*this,aChange,bLocal);
83 // ---------------------------------------------------------------------------------------------------
85 Broadcaster Notifier::makeBroadcaster(configuration::NodeChanges const& aChanges, bool bLocal) const
87 OSL_ENSURE(!aChanges.isEmpty(),"Creating broadcaster for no changes");
88 return Broadcaster(*this,aChanges,bLocal);
90 // ---------------------------------------------------------------------------------------------------
92 NotifierImpl::NotifierImpl(rtl::Reference< configuration::Tree > const& aTree)
93 : m_aListeners(aTree->nodeCount(), SubNodeToIndex(aTree))
96 // ---------------------------------------------------------------------------------------------------
98 NotifierImpl::~NotifierImpl()
102 // ---------------------------------------------------------------------------------------------------
104 void Notifier::add(configuration::NodeRef const& aNode, uno::Reference< css::lang::XEventListener > const& xListener) const
106 if (xListener.is())
107 m_aImpl->add( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
109 // ---------------------------------------------------------------------------------------------------
111 void Notifier::add(configuration::NodeRef const& aNode, uno::Reference< css::container::XContainerListener > const& xListener) const
113 if (xListener.is())
114 m_aImpl->add( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
116 // ---------------------------------------------------------------------------------------------------
118 void Notifier::add(configuration::NodeRef const& aNode, uno::Reference< css::util::XChangesListener > const& xListener) const
120 if (xListener.is())
121 m_aImpl->add( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
123 // ---------------------------------------------------------------------------------------------------
125 void Notifier::addForAll(configuration::NodeRef const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener) const
127 if (xListener.is())
128 m_aImpl->addForAll( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
130 // ---------------------------------------------------------------------------------------------------
132 void Notifier::addForOne(configuration::NodeRef const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener, rtl::OUString const& aName) const
134 if (xListener.is())
135 m_aImpl->addNamed( configuration::SubNodeID(m_pTree->getTree(),aNode, aName), xListener );
137 // ---------------------------------------------------------------------------------------------------
139 void Notifier::addForAll(configuration::NodeRef const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener) const
141 if (xListener.is())
142 m_aImpl->addForAll( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
144 // ---------------------------------------------------------------------------------------------------
146 void Notifier::addForOne(configuration::NodeRef const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener, rtl::OUString const& aName) const
148 if (xListener.is())
149 m_aImpl->addNamed( configuration::SubNodeID(m_pTree->getTree(),aNode, aName), xListener );
151 // ---------------------------------------------------------------------------------------------------
153 void Notifier::add(configuration::NodeRef const& aNode, uno::Reference< css::beans::XPropertiesChangeListener > const& xListener, uno::Sequence<rtl::OUString> const& aNames) const
155 if (xListener.is())
157 if (aNames.getLength() > 0)
158 m_aImpl->add( configuration::NodeID(m_pTree->getTree(),aNode), xListener, aNames);
159 else
160 m_aImpl->add( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
163 // ---------------------------------------------------------------------------------------------------
165 void Notifier::remove(configuration::NodeRef const& aNode, uno::Reference< css::lang::XEventListener > const& xListener) const
167 if (xListener.is())
168 m_aImpl->remove( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
170 // ---------------------------------------------------------------------------------------------------
172 void Notifier::remove(configuration::NodeRef const& aNode, uno::Reference< css::container::XContainerListener > const& xListener) const
174 if (xListener.is())
175 m_aImpl->remove( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
177 // ---------------------------------------------------------------------------------------------------
179 void Notifier::remove(configuration::NodeRef const& aNode, uno::Reference< css::util::XChangesListener > const& xListener) const
181 if (xListener.is())
182 m_aImpl->remove( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
184 // ---------------------------------------------------------------------------------------------------
186 void Notifier::removeForAll(configuration::NodeRef const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener) const
188 if (xListener.is())
189 m_aImpl->removeForAll( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
191 // ---------------------------------------------------------------------------------------------------
193 void Notifier::removeForOne(configuration::NodeRef const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener, rtl::OUString const& aName) const
195 if (xListener.is())
196 m_aImpl->removeNamed( configuration::SubNodeID(m_pTree->getTree(),aNode, aName), xListener );
198 // ---------------------------------------------------------------------------------------------------
200 void Notifier::removeForAll(configuration::NodeRef const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener) const
202 if (xListener.is())
203 m_aImpl->removeForAll( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
205 // ---------------------------------------------------------------------------------------------------
207 void Notifier::removeForOne(configuration::NodeRef const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener, rtl::OUString const& aName) const
209 if (xListener.is())
210 m_aImpl->removeNamed( configuration::SubNodeID(m_pTree->getTree(),aNode, aName), xListener );
212 // ---------------------------------------------------------------------------------------------------
214 void Notifier::remove(configuration::NodeRef const& aNode, uno::Reference< css::beans::XPropertiesChangeListener > const& xListener) const
216 if (xListener.is())
217 m_aImpl->remove( configuration::NodeID(m_pTree->getTree(),aNode), xListener );
220 // ---------------------------------------------------------------------------------------------------
221 // ---------------------------------------------------------------------------------------------------
223 DisposeGuardImpl::DisposeGuardImpl(Notifier const&) throw()
226 // ---------------------------------------------------------------------------------------------------
227 DisposeGuardImpl::~DisposeGuardImpl() throw ()
230 // ---------------------------------------------------------------------------------------------------
231 GuardedNotifier::GuardedNotifier(NodeAccess& rNode) throw()
232 : m_aNotifier(rNode.getNotifier())
233 , m_aImpl(m_aNotifier)
236 // ---------------------------------------------------------------------------------------------------
238 DisposeGuard::DisposeGuard(NodeAccess& rNode) throw(css::lang::DisposedException)
239 : m_aImpl(rNode.getNotifier())
241 rNode.checkAlive();
243 // ---------------------------------------------------------------------------------------------------