1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propmultiplex.cxx,v $
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_comphelper.hxx"
33 #include <comphelper/propmultiplex.hxx>
34 #include <osl/diagnose.h>
36 //.........................................................................
39 //.........................................................................
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::beans
;
45 //========================================================================
46 //= OPropertyChangeListener
47 //========================================================================
48 //------------------------------------------------------------------------
49 OPropertyChangeListener::~OPropertyChangeListener()
52 m_pAdapter
->dispose();
55 //------------------------------------------------------------------
56 void OPropertyChangeListener::_disposing(const EventObject
&) throw( RuntimeException
)
61 //------------------------------------------------------------------
62 void OPropertyChangeListener::disposeAdapter()
65 m_pAdapter
->dispose();
67 // will automatically set a new adapter
68 OSL_ENSURE( !m_pAdapter
, "OPropertyChangeListener::disposeAdapter: what did dispose do?" );
71 //------------------------------------------------------------------
72 void OPropertyChangeListener::setAdapter(OPropertyChangeMultiplexer
* pAdapter
)
76 ::osl::MutexGuard
aGuard(m_rMutex
);
77 m_pAdapter
->release();
83 ::osl::MutexGuard
aGuard(m_rMutex
);
84 m_pAdapter
= pAdapter
;
85 m_pAdapter
->acquire();
89 //========================================================================
90 //= OPropertyChangeMultiplexer
91 //========================================================================
92 //------------------------------------------------------------------
93 OPropertyChangeMultiplexer::OPropertyChangeMultiplexer(OPropertyChangeListener
* _pListener
, const Reference
< XPropertySet
>& _rxSet
, sal_Bool _bAutoReleaseSet
)
95 ,m_pListener(_pListener
)
97 ,m_bListening(sal_False
)
98 ,m_bAutoSetRelease(_bAutoReleaseSet
)
100 m_pListener
->setAdapter(this);
103 //------------------------------------------------------------------
104 OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer()
108 //------------------------------------------------------------------
109 void OPropertyChangeMultiplexer::lock()
114 //------------------------------------------------------------------
115 void OPropertyChangeMultiplexer::unlock()
120 //------------------------------------------------------------------
121 void OPropertyChangeMultiplexer::dispose()
125 Reference
< XPropertyChangeListener
> xPreventDelete(this);
127 const ::rtl::OUString
* pProperties
= m_aProperties
.getConstArray();
128 for (sal_Int32 i
= 0; i
< m_aProperties
.getLength(); ++i
, ++pProperties
)
129 m_xSet
->removePropertyChangeListener(*pProperties
, static_cast< XPropertyChangeListener
*>(this));
131 m_pListener
->setAdapter(NULL
);
134 m_bListening
= sal_False
;
136 if (m_bAutoSetRelease
)
142 //------------------------------------------------------------------
143 void SAL_CALL
OPropertyChangeMultiplexer::disposing( const EventObject
& _rSource
) throw( RuntimeException
)
149 m_pListener
->_disposing(_rSource
);
150 // disconnect the listener
151 if (m_pListener
) // may have been reset whilest calling into _disposing
152 m_pListener
->setAdapter(NULL
);
156 m_bListening
= sal_False
;
158 if (m_bAutoSetRelease
)
162 // XPropertyChangeListener
163 //------------------------------------------------------------------
164 void SAL_CALL
OPropertyChangeMultiplexer::propertyChange( const PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
166 if (m_pListener
&& !locked())
167 m_pListener
->_propertyChanged(_rEvent
);
170 //------------------------------------------------------------------
171 void OPropertyChangeMultiplexer::addProperty(const ::rtl::OUString
& _sPropertyName
)
175 m_xSet
->addPropertyChangeListener(_sPropertyName
, static_cast< XPropertyChangeListener
*>(this));
176 m_aProperties
.realloc(m_aProperties
.getLength() + 1);
177 m_aProperties
.getArray()[m_aProperties
.getLength()-1] = _sPropertyName
;
178 m_bListening
= sal_True
;
182 //.........................................................................
184 //.........................................................................