merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / api2 / notifierimpl.hxx
blob445ef00d3164dd90384263a37d4b5d502ad45ace
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: notifierimpl.hxx,v $
10 * $Revision: 1.10 $
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 #ifndef CONFIGMGR_API_NOTIFIERIMPL_HXX_
32 #define CONFIGMGR_API_NOTIFIERIMPL_HXX_
34 #include "listenercontainer.hxx"
36 #include "noderef.hxx"
37 #include "valueref.hxx"
39 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
40 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
41 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
42 #include <com/sun/star/beans/PropertyVetoException.hpp>
43 #include <com/sun/star/container/XContainerListener.hpp>
44 #include <com/sun/star/util/XChangesListener.hpp>
46 #include "propertiesfilterednotifier.hxx"
48 #include <vos/refernce.hxx>
50 namespace configmgr
52 namespace configapi
54 // ---------------------------------------------------------------------------------------------------
56 struct SubNodeHash
58 size_t operator() (const configuration::SubNodeID& rKey) const {return rKey.hashCode();}
60 struct SubNodeEq
62 bool operator() (const configuration::SubNodeID& lhs,const configuration::SubNodeID& rhs) const {return lhs == rhs;}
64 struct SubNodeToIndex
66 rtl::Reference< configuration::Tree > aTree;
68 SubNodeToIndex( rtl::Reference< configuration::Tree > const& rTree ) : aTree(rTree) {}
70 bool findKeysForIndex(unsigned int nNode, std::vector<configuration::SubNodeID>& aList)
72 aList.clear();
73 configuration::getAllChildrenHelper(configuration::findNodeFromIndex(aTree,nNode), aList);
74 return !aList.empty();
76 unsigned int findIndexForKey(configuration::SubNodeID const& aNode)
78 return aNode.getParentID().toIndex();
82 /// manages collections of event listeners observing a whole config tree, thread-safe
83 class NotifierImpl : public vos::OReference
85 public:
86 SpecialListenerContainer <configuration::SubNodeID,SubNodeHash,SubNodeEq,SubNodeToIndex> m_aListeners;
88 public:
89 /// construct this around the given Implementation, for the given tree
90 explicit
91 NotifierImpl(rtl::Reference< configuration::Tree > const& aTree);
92 ~NotifierImpl();
94 /// Add a <type scope='com::sun::star::lang'>XEventListener</type> observing <var>aNode</var>.
95 void add(configuration::NodeID const& aNode, uno::Reference< css::lang::XEventListener > const& xListener)
97 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
99 // ignore the names for now
100 m_aListeners.addListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
103 /// Add a <type scope='com::sun::star::container'>XContainerListener</type> observing <var>aNode</var>.
104 void add(configuration::NodeID const& aNode, uno::Reference< css::container::XContainerListener > const& xListener)
106 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
108 // ignore the names for now
109 m_aListeners.addListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
112 /// Add a <type scope='com::sun::star::util'>XChangesListener</type> observing <var>aNode</var> and its descendants.
113 void add(configuration::NodeID const& aNode, uno::Reference< css::util::XChangesListener > const& xListener)
115 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
117 // ignore the names for now
118 m_aListeners.addListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
121 /// Add a <type scope='com::sun::star::beans'>XPropertyChangeListener</type> observing <var>aNode</var>.
122 void addNamed(configuration::SubNodeID const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener)
124 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
126 // ignore the names for now
127 m_aListeners.addSpecialListener(aNode,xListener.get());
129 /// Add a <type scope='com::sun::star::beans'>XPropertyChangeListener</type> observing <var>aNode</var>.
130 void addForAll(configuration::NodeID const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener)
132 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
134 // ignore the names for now
135 m_aListeners.addListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
137 /// Add a <type scope='com::sun::star::beans'>XVetoableChangeListener</type> constraining <var>aNode</var>.
138 void addNamed(configuration::SubNodeID const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener)
140 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
142 // ignore the names for now
143 m_aListeners.addSpecialListener(aNode,xListener.get());
145 /// Add a <type scope='com::sun::star::beans'>XVetoableChangeListener</type> constraining <var>aNode</var>.
146 void addForAll(configuration::NodeID const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener)
148 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
150 // ignore the names for now
151 m_aListeners.addListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
154 /** Add a <type scope='com::sun::star::beans'>XPropertiesChangeListener</type>
155 observing all properties of <var>aNode</var>.
157 void add(configuration::NodeID const& aNode, uno::Reference< css::beans::XPropertiesChangeListener > const& xListener)
159 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
161 // ignore the names for now
162 m_aListeners.addListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
165 /** Add a <type scope='com::sun::star::beans'>XPropertiesChangeListener</type>
166 observing the properties of <var>aNode</var> (optimally only those given by <var>aNames</var>.
168 void add(configuration::NodeID const& aNode, uno::Reference< css::beans::XPropertiesChangeListener > const& xListener, uno::Sequence< rtl::OUString> const& aNames)
170 OSL_PRECOND(xListener.is(), "ERROR: Unexpected NULL listener");
171 OSL_PRECOND(aNames.getLength() > 0, "ERROR: Unexpected empty sequence");
173 uno::Reference< css::beans::XPropertiesChangeListener > xForwarder( new PropertiesFilteredNotifier(xListener,aNames) );
174 // ignore the names for now
175 add(aNode,xForwarder);
178 // ---------------------------------------------------------------------------------------------------
179 /// Remove a <type scope='com::sun::star::lang'>XEventListener</type> observing <var>aNode</var>.
180 void remove(configuration::NodeID const& aNode, uno::Reference< css::lang::XEventListener > const& xListener)
182 // ignore the names for now
183 m_aListeners.removeListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
186 /// Remove a <type scope='com::sun::star::container'>XContainerListener</type> observing <var>aNode</var>.
187 void remove(configuration::NodeID const& aNode, uno::Reference< css::container::XContainerListener > const& xListener)
189 // ignore the names for now
190 m_aListeners.removeListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
193 /// Remove a <type scope='com::sun::star::util'>XChangesListener</type> observing <var>aNode</var> and its descendants.
194 void remove(configuration::NodeID const& aNode, uno::Reference< css::util::XChangesListener > const& xListener)
196 // ignore the names for now
197 m_aListeners.removeListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
200 /// Remove a <type scope='com::sun::star::beans'>XPropertyChangeListener</type> observing <var>aNode</var>.
201 void removeNamed(configuration::SubNodeID const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener)
203 // ignore the names for now
204 m_aListeners.removeSpecialListener(aNode,xListener.get());
206 /// Remove a <type scope='com::sun::star::beans'>XPropertyChangeListener</type> observing <var>aNode</var>.
207 void removeForAll(configuration::NodeID const& aNode, uno::Reference< css::beans::XPropertyChangeListener > const& xListener)
209 // ignore the names for now
210 m_aListeners.removeListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
212 /// Remove a <type scope='com::sun::star::beans'>XVetoableChangeListener</type> constraining <var>aNode</var>.
213 void removeNamed(configuration::SubNodeID const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener)
215 // ignore the names for now
216 m_aListeners.removeSpecialListener(aNode,xListener.get());
218 /// Remove a <type scope='com::sun::star::beans'>XVetoableChangeListener</type> constraining <var>aNode</var>.
219 void removeForAll(configuration::NodeID const& aNode, uno::Reference< css::beans::XVetoableChangeListener > const& xListener)
221 // ignore the names for now
222 m_aListeners.removeListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
226 /** Remove a <type scope='com::sun::star::beans'>XPropertiesChangeListener</type>
227 observing any properties of <var>aNode</var>.
229 void remove(configuration::NodeID const& aNode, uno::Reference< css::beans::XPropertiesChangeListener > const& xListener)
231 // ignore the names for now
232 m_aListeners.removeListener(aNode.toIndex(),getCppuType(&xListener),xListener.get());
234 // ---------------------------------------------------------------------------------------------------
237 // ---------------------------------------------------------------------------------------------------
241 #endif // CONFIGMGR_API_NOTIFIERIMPL_HXX_