Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "tools/PropertySet.hxx"
31 : : #include <algorithm>
32 : : #include <o3tl/compat_functional.hxx>
33 : :
34 : : using namespace ::com::sun::star;
35 : : using namespace ::com::sun::star::uno;
36 : : using ::rtl::OUString;
37 : :
38 : : namespace sd { namespace tools {
39 : :
40 : 0 : PropertySet::PropertySet (void)
41 : : : PropertySetInterfaceBase(m_aMutex),
42 [ # # ][ # # ]: 0 : mpChangeListeners(new ChangeListenerContainer())
43 : : {
44 : 0 : }
45 : :
46 : :
47 : :
48 : :
49 [ # # ][ # # ]: 0 : PropertySet::~PropertySet (void)
50 : : {
51 [ # # ]: 0 : }
52 : :
53 : :
54 : :
55 : :
56 : 0 : void SAL_CALL PropertySet::disposing (void)
57 : : {
58 : 0 : }
59 : :
60 : : //----- XPropertySet ----------------------------------------------------------
61 : :
62 : 0 : Reference<beans::XPropertySetInfo> SAL_CALL PropertySet::getPropertySetInfo (void)
63 : : throw(RuntimeException)
64 : : {
65 : 0 : return NULL;
66 : : }
67 : :
68 : :
69 : :
70 : :
71 : 0 : void SAL_CALL PropertySet::setPropertyValue (
72 : : const rtl::OUString& rsPropertyName,
73 : : const css::uno::Any& rsPropertyValue)
74 : : throw(css::beans::UnknownPropertyException,
75 : : css::beans::PropertyVetoException,
76 : : css::lang::IllegalArgumentException,
77 : : css::lang::WrappedTargetException,
78 : : css::uno::RuntimeException)
79 : : {
80 [ # # ]: 0 : ThrowIfDisposed();
81 : :
82 [ # # ]: 0 : Any aOldValue (SetPropertyValue(rsPropertyName,rsPropertyValue));
83 [ # # ]: 0 : if (aOldValue != rsPropertyValue)
84 : : {
85 : : // Inform listeners that are registered specifically for the
86 : : // property and those registered for any property.
87 : : beans::PropertyChangeEvent aEvent(
88 : : static_cast<XWeak*>(this),
89 : : rsPropertyName,
90 : : sal_False,
91 : : -1,
92 : : aOldValue,
93 [ # # ][ # # ]: 0 : rsPropertyValue);
94 [ # # ]: 0 : CallListeners(rsPropertyName, aEvent);
95 [ # # ][ # # ]: 0 : CallListeners(OUString(), aEvent);
96 : 0 : }
97 : 0 : }
98 : :
99 : :
100 : :
101 : :
102 : 0 : Any SAL_CALL PropertySet::getPropertyValue (const OUString& rsPropertyName)
103 : : throw(css::beans::UnknownPropertyException,
104 : : css::lang::WrappedTargetException,
105 : : css::uno::RuntimeException)
106 : : {
107 : 0 : ThrowIfDisposed();
108 : :
109 : 0 : return GetPropertyValue(rsPropertyName);
110 : : }
111 : :
112 : :
113 : :
114 : :
115 : 0 : void SAL_CALL PropertySet::addPropertyChangeListener (
116 : : const rtl::OUString& rsPropertyName,
117 : : const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
118 : : throw(css::beans::UnknownPropertyException,
119 : : css::lang::WrappedTargetException,
120 : : css::uno::RuntimeException)
121 : : {
122 [ # # ]: 0 : if ( ! rxListener.is())
123 [ # # ]: 0 : throw lang::IllegalArgumentException();
124 : :
125 [ # # ][ # # ]: 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
126 : 0 : return;
127 : :
128 : : mpChangeListeners->insert(
129 : : ChangeListenerContainer::value_type(
130 : : rsPropertyName,
131 [ # # ]: 0 : rxListener));
132 : : }
133 : :
134 : :
135 : :
136 : :
137 : 0 : void SAL_CALL PropertySet::removePropertyChangeListener (
138 : : const rtl::OUString& rsPropertyName,
139 : : const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
140 : : throw(beans::UnknownPropertyException,
141 : : css::lang::WrappedTargetException,
142 : : css::uno::RuntimeException)
143 : : {
144 : : ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
145 [ # # ]: 0 : aRange (mpChangeListeners->equal_range(rsPropertyName));
146 : :
147 : : ChangeListenerContainer::iterator iListener (
148 : : ::std::find_if(
149 : : aRange.first,
150 : : aRange.second,
151 : : o3tl::compose1(
152 : : std::bind1st(std::equal_to<Reference<beans::XPropertyChangeListener> >(),
153 : : rxListener),
154 [ # # ][ # # ]: 0 : o3tl::select2nd<ChangeListenerContainer::value_type>())));
[ # # ][ # # ]
[ # # ]
155 [ # # ]: 0 : if (iListener != mpChangeListeners->end())
156 : : {
157 [ # # ]: 0 : mpChangeListeners->erase(iListener);
158 : : }
159 : : else
160 : : {
161 [ # # ]: 0 : throw lang::IllegalArgumentException();
162 : : }
163 : 0 : }
164 : :
165 : :
166 : :
167 : :
168 : 0 : void SAL_CALL PropertySet::addVetoableChangeListener (
169 : : const rtl::OUString& rsPropertyName,
170 : : const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
171 : : throw(css::beans::UnknownPropertyException,
172 : : css::lang::WrappedTargetException,
173 : : css::uno::RuntimeException)
174 : : {
175 : : // Constraint properties are not supported and thus no vetoable
176 : : // listeners.
177 : : (void)rsPropertyName;
178 : : (void)rxListener;
179 : 0 : }
180 : :
181 : :
182 : :
183 : :
184 : 0 : void SAL_CALL PropertySet::removeVetoableChangeListener (
185 : : const rtl::OUString& rsPropertyName,
186 : : const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
187 : : throw(css::beans::UnknownPropertyException,
188 : : css::lang::WrappedTargetException,
189 : : css::uno::RuntimeException)
190 : : {
191 : : // Constraint properties are not supported and thus no vetoable
192 : : // listeners.
193 : : (void)rsPropertyName;
194 : : (void)rxListener;
195 : 0 : }
196 : :
197 : :
198 : :
199 : :
200 : : //-----------------------------------------------------------------------------
201 : :
202 : 0 : void PropertySet::CallListeners (
203 : : const rtl::OUString& rsPropertyName,
204 : : const beans::PropertyChangeEvent& rEvent)
205 : : {
206 : : ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator>
207 [ # # ]: 0 : aRange (mpChangeListeners->equal_range(rsPropertyName));
208 : 0 : ChangeListenerContainer::const_iterator iListener;
209 [ # # ]: 0 : for (iListener=aRange.first; iListener!=aRange.second; ++iListener)
210 : : {
211 [ # # ]: 0 : if (iListener->second.is())
212 [ # # ][ # # ]: 0 : iListener->second->propertyChange(rEvent);
213 : : }
214 : 0 : }
215 : :
216 : :
217 : :
218 : :
219 : 0 : void PropertySet::ThrowIfDisposed (void)
220 : : throw (::com::sun::star::lang::DisposedException)
221 : : {
222 [ # # ][ # # ]: 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
223 : : {
224 : : throw lang::DisposedException (
225 : : "PropertySet object has already been disposed",
226 [ # # ][ # # ]: 0 : static_cast<uno::XWeak*>(this));
227 : : }
228 : 0 : }
229 : :
230 : : } } // end of namespace ::sd::tools
231 : :
232 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|