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 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "precompiled_sd.hxx" 25 26 #include "tools/PropertySet.hxx" 27 #include <boost/bind.hpp> 28 #include <algorithm> 29 #include <functional> 30 31 using namespace ::com::sun::star; 32 using namespace ::com::sun::star::uno; 33 using ::rtl::OUString; 34 35 namespace sd { namespace tools { 36 37 PropertySet::PropertySet (void) 38 : PropertySetInterfaceBase(m_aMutex), 39 mpChangeListeners(new ChangeListenerContainer()) 40 { 41 } 42 43 44 45 46 PropertySet::~PropertySet (void) 47 { 48 } 49 50 51 52 53 void SAL_CALL PropertySet::disposing (void) 54 { 55 } 56 57 //----- XPropertySet ---------------------------------------------------------- 58 59 Reference<beans::XPropertySetInfo> SAL_CALL PropertySet::getPropertySetInfo (void) 60 throw(RuntimeException) 61 { 62 return NULL; 63 } 64 65 66 67 68 void SAL_CALL PropertySet::setPropertyValue ( 69 const rtl::OUString& rsPropertyName, 70 const css::uno::Any& rsPropertyValue) 71 throw(css::beans::UnknownPropertyException, 72 css::beans::PropertyVetoException, 73 css::lang::IllegalArgumentException, 74 css::lang::WrappedTargetException, 75 css::uno::RuntimeException) 76 { 77 ThrowIfDisposed(); 78 79 Any aOldValue (SetPropertyValue(rsPropertyName,rsPropertyValue)); 80 if (aOldValue != rsPropertyValue) 81 { 82 // Inform listeners that are registered specifically for the 83 // property and those registered for any property. 84 beans::PropertyChangeEvent aEvent( 85 static_cast<XWeak*>(this), 86 rsPropertyName, 87 sal_False, 88 -1, 89 aOldValue, 90 rsPropertyValue); 91 CallListeners(rsPropertyName, aEvent); 92 CallListeners(OUString(), aEvent); 93 } 94 } 95 96 97 98 99 Any SAL_CALL PropertySet::getPropertyValue (const OUString& rsPropertyName) 100 throw(css::beans::UnknownPropertyException, 101 css::lang::WrappedTargetException, 102 css::uno::RuntimeException) 103 { 104 ThrowIfDisposed(); 105 106 return GetPropertyValue(rsPropertyName); 107 } 108 109 110 111 112 void SAL_CALL PropertySet::addPropertyChangeListener ( 113 const rtl::OUString& rsPropertyName, 114 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener) 115 throw(css::beans::UnknownPropertyException, 116 css::lang::WrappedTargetException, 117 css::uno::RuntimeException) 118 { 119 if ( ! rxListener.is()) 120 throw lang::IllegalArgumentException(); 121 122 if (rBHelper.bDisposed || rBHelper.bInDispose) 123 return; 124 125 mpChangeListeners->insert( 126 ChangeListenerContainer::value_type( 127 rsPropertyName, 128 rxListener)); 129 } 130 131 132 133 134 void SAL_CALL PropertySet::removePropertyChangeListener ( 135 const rtl::OUString& rsPropertyName, 136 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener) 137 throw(beans::UnknownPropertyException, 138 css::lang::WrappedTargetException, 139 css::uno::RuntimeException) 140 { 141 ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator> 142 aRange (mpChangeListeners->equal_range(rsPropertyName)); 143 144 ChangeListenerContainer::iterator iListener ( 145 ::std::find_if( 146 aRange.first, 147 aRange.second, 148 std::compose1( 149 std::bind1st(std::equal_to<Reference<beans::XPropertyChangeListener> >(), 150 rxListener), 151 std::select2nd<ChangeListenerContainer::value_type>()))); 152 if (iListener != mpChangeListeners->end()) 153 { 154 mpChangeListeners->erase(iListener); 155 } 156 else 157 { 158 throw lang::IllegalArgumentException(); 159 } 160 } 161 162 163 164 165 void SAL_CALL PropertySet::addVetoableChangeListener ( 166 const rtl::OUString& rsPropertyName, 167 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener) 168 throw(css::beans::UnknownPropertyException, 169 css::lang::WrappedTargetException, 170 css::uno::RuntimeException) 171 { 172 // Constraint properties are not supported and thus no vetoable 173 // listeners. 174 (void)rsPropertyName; 175 (void)rxListener; 176 } 177 178 179 180 181 void SAL_CALL PropertySet::removeVetoableChangeListener ( 182 const rtl::OUString& rsPropertyName, 183 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener) 184 throw(css::beans::UnknownPropertyException, 185 css::lang::WrappedTargetException, 186 css::uno::RuntimeException) 187 { 188 // Constraint properties are not supported and thus no vetoable 189 // listeners. 190 (void)rsPropertyName; 191 (void)rxListener; 192 } 193 194 195 196 197 //----------------------------------------------------------------------------- 198 199 void PropertySet::CallListeners ( 200 const rtl::OUString& rsPropertyName, 201 const beans::PropertyChangeEvent& rEvent) 202 { 203 ::std::pair<ChangeListenerContainer::iterator,ChangeListenerContainer::iterator> 204 aRange (mpChangeListeners->equal_range(rsPropertyName)); 205 ChangeListenerContainer::const_iterator iListener; 206 for (iListener=aRange.first; iListener!=aRange.second; ++iListener) 207 { 208 if (iListener->second.is()) 209 iListener->second->propertyChange(rEvent); 210 } 211 } 212 213 214 215 216 void PropertySet::ThrowIfDisposed (void) 217 throw (::com::sun::star::lang::DisposedException) 218 { 219 if (rBHelper.bDisposed || rBHelper.bInDispose) 220 { 221 throw lang::DisposedException ( 222 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 223 "PropertySet object has already been disposed")), 224 static_cast<uno::XWeak*>(this)); 225 } 226 } 227 228 } } // end of namespace ::sd::tools 229