Bump for 3.6-28
[LibreOffice.git] / extensions / source / bibliography / loadlisteneradapter.cxx
blob3d9ed1ac731bf620ea795f0b616f6a3c4a2e0d1f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "loadlisteneradapter.hxx"
30 #include <osl/diagnose.h>
31 #include <rtl/ref.hxx>
33 //.........................................................................
34 namespace bib
36 //.........................................................................
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::form;
42 //=====================================================================
43 //= OComponentListener
44 //=====================================================================
45 //---------------------------------------------------------------------
46 OComponentListener::~OComponentListener()
49 ::osl::MutexGuard aGuard( m_rMutex );
50 if ( m_pAdapter )
51 m_pAdapter->dispose();
55 //---------------------------------------------------------------------
56 void OComponentListener::_disposing( const EventObject& /*_rSource*/ ) throw( RuntimeException)
58 // nothing to do here, overrride if you're interested in
61 //---------------------------------------------------------------------
62 void OComponentListener::setAdapter( OComponentAdapterBase* pAdapter )
65 ::osl::MutexGuard aGuard( m_rMutex );
66 if ( m_pAdapter )
68 m_pAdapter->release();
69 m_pAdapter = NULL;
73 if ( pAdapter )
75 ::osl::MutexGuard aGuard( m_rMutex );
76 m_pAdapter = pAdapter;
77 m_pAdapter->acquire();
81 //=====================================================================
82 //= OComponentAdapterBase
83 //=====================================================================
84 //---------------------------------------------------------------------
85 OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp, sal_Bool _bAutoRelease )
86 :m_xComponent( _rxComp )
87 ,m_pListener( NULL )
88 ,m_nLockCount( 0 )
89 ,m_bListening( sal_False )
90 ,m_bAutoRelease( _bAutoRelease )
92 OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
95 //---------------------------------------------------------------------
96 void OComponentAdapterBase::Init( OComponentListener* _pListener )
98 OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
99 OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
101 m_pListener = _pListener;
102 if ( m_pListener )
103 m_pListener->setAdapter( this );
105 startComponentListening( );
106 m_bListening = sal_True;
109 //---------------------------------------------------------------------
110 OComponentAdapterBase::~OComponentAdapterBase()
114 //---------------------------------------------------------------------
115 void OComponentAdapterBase::dispose()
117 if ( m_bListening )
119 ::rtl::Reference< OComponentAdapterBase > xPreventDelete(this);
121 disposing();
123 m_pListener->setAdapter(NULL);
125 m_pListener = NULL;
126 m_bListening = sal_False;
128 if (m_bAutoRelease)
129 m_xComponent = NULL;
133 // XEventListener
135 //---------------------------------------------------------------------
136 void SAL_CALL OComponentAdapterBase::disposing( const EventObject& _rSource ) throw( RuntimeException )
138 if ( m_pListener )
140 // tell the listener
141 if ( !locked() )
142 m_pListener->_disposing( _rSource );
144 // disconnect the listener
145 if ( m_pListener ) // may have been reset whilest calling into _disposing
146 m_pListener->setAdapter( NULL );
149 m_pListener = NULL;
150 m_bListening = sal_False;
152 if ( m_bAutoRelease )
153 m_xComponent = NULL;
156 //=====================================================================
157 //= OLoadListenerAdapter
158 //=====================================================================
159 //---------------------------------------------------------------------
160 OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable, sal_Bool _bAutoRelease )
161 :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ), _bAutoRelease )
165 //---------------------------------------------------------------------
166 void OLoadListenerAdapter::startComponentListening()
168 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
169 OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
170 if ( xLoadable.is() )
171 xLoadable->addLoadListener( this );
174 //---------------------------------------------------------------------
175 void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
177 OLoadListenerAdapter_Base::acquire();
180 //---------------------------------------------------------------------
181 void SAL_CALL OLoadListenerAdapter::release( ) throw ()
183 OLoadListenerAdapter_Base::release();
186 //---------------------------------------------------------------------
187 void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource ) throw( RuntimeException)
189 OComponentAdapterBase::disposing( _rSource );
192 //---------------------------------------------------------------------
193 void OLoadListenerAdapter::disposing()
195 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
196 if ( xLoadable.is() )
197 xLoadable->removeLoadListener( this );
200 //---------------------------------------------------------------------
201 void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent ) throw (RuntimeException)
203 if ( !locked() && getLoadListener( ) )
204 getLoadListener( )->_loaded( _rEvent );
207 //---------------------------------------------------------------------
208 void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent ) throw (RuntimeException)
210 if ( !locked() && getLoadListener( ) )
211 getLoadListener( )->_unloading( _rEvent );
214 //---------------------------------------------------------------------
215 void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& _rEvent ) throw (RuntimeException)
217 if ( !locked() && getLoadListener( ) )
218 getLoadListener( )->_unloaded( _rEvent );
221 //---------------------------------------------------------------------
222 void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent ) throw (RuntimeException)
224 if ( !locked() && getLoadListener( ) )
225 getLoadListener( )->_reloading( _rEvent );
228 //---------------------------------------------------------------------
229 void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent ) throw (RuntimeException)
231 if ( !locked() && getLoadListener( ) )
232 getLoadListener( )->_reloaded( _rEvent );
235 //.........................................................................
236 } // namespace bib
237 //.........................................................................
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */