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