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: SelectionMultiplex.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"
34 #include <comphelper/SelectionMultiplex.hxx>
35 #include <osl/diagnose.h>
37 //.........................................................................
40 //.........................................................................
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::view
;
46 //========================================================================
47 //= OSelectionChangeListener
48 //========================================================================
49 //------------------------------------------------------------------------
50 OSelectionChangeListener::~OSelectionChangeListener()
53 m_pAdapter
->dispose();
56 //------------------------------------------------------------------
57 void OSelectionChangeListener::_disposing(const EventObject
&) throw( RuntimeException
)
62 //------------------------------------------------------------------
63 void OSelectionChangeListener::disposeAdapter()
66 m_pAdapter
->dispose();
68 // will automatically set a new adapter
69 OSL_ENSURE( !m_pAdapter
, "OSelectionChangeListener::disposeAdapter: what did dispose do?" );
72 //------------------------------------------------------------------
73 void OSelectionChangeListener::setAdapter(OSelectionChangeMultiplexer
* pAdapter
)
77 ::osl::MutexGuard
aGuard(m_rMutex
);
78 m_pAdapter
->release();
84 ::osl::MutexGuard
aGuard(m_rMutex
);
85 m_pAdapter
= pAdapter
;
86 m_pAdapter
->acquire();
90 //========================================================================
91 //= OSelectionChangeMultiplexer
92 //========================================================================
93 //------------------------------------------------------------------
94 OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener
* _pListener
, const Reference
< XSelectionSupplier
>& _rxSet
, sal_Bool _bAutoReleaseSet
)
96 ,m_pListener(_pListener
)
98 ,m_bListening(sal_False
)
99 ,m_bAutoSetRelease(_bAutoReleaseSet
)
101 m_pListener
->setAdapter(this);
102 osl_incrementInterlockedCount(&m_refCount
);
104 Reference
< XSelectionChangeListener
> xPreventDelete(this);
105 m_xSet
->addSelectionChangeListener(xPreventDelete
);
107 osl_decrementInterlockedCount(&m_refCount
);
110 //------------------------------------------------------------------
111 OSelectionChangeMultiplexer::~OSelectionChangeMultiplexer()
115 //------------------------------------------------------------------
116 void OSelectionChangeMultiplexer::lock()
121 //------------------------------------------------------------------
122 void OSelectionChangeMultiplexer::unlock()
127 //------------------------------------------------------------------
128 void OSelectionChangeMultiplexer::dispose()
132 Reference
< XSelectionChangeListener
> xPreventDelete(this);
134 m_xSet
->removeSelectionChangeListener(xPreventDelete
);
136 m_pListener
->setAdapter(NULL
);
139 m_bListening
= sal_False
;
141 if (m_bAutoSetRelease
)
147 //------------------------------------------------------------------
148 void SAL_CALL
OSelectionChangeMultiplexer::disposing( const EventObject
& _rSource
) throw( RuntimeException
)
154 m_pListener
->_disposing(_rSource
);
155 // disconnect the listener
156 if (m_pListener
) // may have been reset whilest calling into _disposing
157 m_pListener
->setAdapter(NULL
);
161 m_bListening
= sal_False
;
163 if (m_bAutoSetRelease
)
167 // XSelectionChangeListener
168 //------------------------------------------------------------------
169 void SAL_CALL
OSelectionChangeMultiplexer::selectionChanged( const EventObject
& _rEvent
) throw( RuntimeException
)
171 if (m_pListener
&& !locked())
172 m_pListener
->_selectionChanged(_rEvent
);
174 //.........................................................................
176 //.........................................................................