update dev300-m58
[ooovba.git] / extensions / source / bibliography / loadlisteneradapter.cxx
blob04c93525df94bfcc9befe25ef586e18ae9cfc631
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loadlisteneradapter.cxx,v $
10 * $Revision: 1.7.68.1 $
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_extensions.hxx"
33 #include "loadlisteneradapter.hxx"
34 #include <osl/diagnose.h>
35 #include <vos/ref.hxx>
37 //.........................................................................
38 namespace bib
40 //.........................................................................
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::form;
46 //=====================================================================
47 //= OComponentListener
48 //=====================================================================
49 //---------------------------------------------------------------------
50 OComponentListener::~OComponentListener()
53 ::osl::MutexGuard aGuard( m_rMutex );
54 if ( m_pAdapter )
55 m_pAdapter->dispose();
59 //---------------------------------------------------------------------
60 void OComponentListener::_disposing( const EventObject& /*_rSource*/ ) throw( RuntimeException)
62 // nothing to do here, overrride if you're interested in
65 //---------------------------------------------------------------------
66 void OComponentListener::setAdapter( OComponentAdapterBase* pAdapter )
69 ::osl::MutexGuard aGuard( m_rMutex );
70 if ( m_pAdapter )
72 m_pAdapter->release();
73 m_pAdapter = NULL;
77 if ( pAdapter )
79 ::osl::MutexGuard aGuard( m_rMutex );
80 m_pAdapter = pAdapter;
81 m_pAdapter->acquire();
85 //=====================================================================
86 //= OComponentAdapterBase
87 //=====================================================================
88 //---------------------------------------------------------------------
89 OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp, sal_Bool _bAutoRelease )
90 :m_xComponent( _rxComp )
91 ,m_pListener( NULL )
92 ,m_nLockCount( 0 )
93 ,m_bListening( sal_False )
94 ,m_bAutoRelease( _bAutoRelease )
96 OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
99 //---------------------------------------------------------------------
100 void OComponentAdapterBase::Init( OComponentListener* _pListener )
102 OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
103 OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
105 m_pListener = _pListener;
106 if ( m_pListener )
107 m_pListener->setAdapter( this );
109 startComponentListening( );
110 m_bListening = sal_True;
113 //---------------------------------------------------------------------
114 OComponentAdapterBase::~OComponentAdapterBase()
118 //---------------------------------------------------------------------
119 void OComponentAdapterBase::dispose()
121 if ( m_bListening )
123 ::vos::ORef< OComponentAdapterBase > xPreventDelete(this);
125 disposing();
127 m_pListener->setAdapter(NULL);
129 m_pListener = NULL;
130 m_bListening = sal_False;
132 if (m_bAutoRelease)
133 m_xComponent = NULL;
137 // XEventListener
139 //---------------------------------------------------------------------
140 void SAL_CALL OComponentAdapterBase::disposing( const EventObject& _rSource ) throw( RuntimeException )
142 if ( m_pListener )
144 // tell the listener
145 if ( !locked() )
146 m_pListener->_disposing( _rSource );
148 // disconnect the listener
149 if ( m_pListener ) // may have been reset whilest calling into _disposing
150 m_pListener->setAdapter( NULL );
153 m_pListener = NULL;
154 m_bListening = sal_False;
156 if ( m_bAutoRelease )
157 m_xComponent = NULL;
160 //=====================================================================
161 //= OLoadListenerAdapter
162 //=====================================================================
163 //---------------------------------------------------------------------
164 OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable, sal_Bool _bAutoRelease )
165 :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ), _bAutoRelease )
169 //---------------------------------------------------------------------
170 void OLoadListenerAdapter::startComponentListening()
172 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
173 OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
174 if ( xLoadable.is() )
175 xLoadable->addLoadListener( this );
178 //---------------------------------------------------------------------
179 void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
181 OLoadListenerAdapter_Base::acquire();
184 //---------------------------------------------------------------------
185 void SAL_CALL OLoadListenerAdapter::release( ) throw ()
187 OLoadListenerAdapter_Base::release();
190 //---------------------------------------------------------------------
191 void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource ) throw( RuntimeException)
193 OComponentAdapterBase::disposing( _rSource );
196 //---------------------------------------------------------------------
197 void OLoadListenerAdapter::disposing()
199 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
200 if ( xLoadable.is() )
201 xLoadable->removeLoadListener( this );
204 //---------------------------------------------------------------------
205 void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent ) throw (RuntimeException)
207 if ( !locked() && getLoadListener( ) )
208 getLoadListener( )->_loaded( _rEvent );
211 //---------------------------------------------------------------------
212 void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent ) throw (RuntimeException)
214 if ( !locked() && getLoadListener( ) )
215 getLoadListener( )->_unloading( _rEvent );
218 //---------------------------------------------------------------------
219 void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& _rEvent ) throw (RuntimeException)
221 if ( !locked() && getLoadListener( ) )
222 getLoadListener( )->_unloaded( _rEvent );
225 //---------------------------------------------------------------------
226 void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent ) throw (RuntimeException)
228 if ( !locked() && getLoadListener( ) )
229 getLoadListener( )->_reloading( _rEvent );
232 //---------------------------------------------------------------------
233 void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent ) throw (RuntimeException)
235 if ( !locked() && getLoadListener( ) )
236 getLoadListener( )->_reloaded( _rEvent );
239 //.........................................................................
240 } // namespace bib
241 //.........................................................................