Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / bibliography / loadlisteneradapter.cxx
blob7b5d4d61d29ed00958440b9780c0849c034d7153
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "loadlisteneradapter.hxx"
21 #include <osl/diagnose.h>
22 #include <rtl/ref.hxx>
25 namespace bib
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::form;
33 OComponentListener::~OComponentListener()
35 ::osl::MutexGuard aGuard( m_rMutex );
36 if ( m_xAdapter.is() )
37 m_xAdapter->dispose();
41 void OComponentListener::setAdapter( OComponentAdapterBase* pAdapter )
43 ::osl::MutexGuard aGuard( m_rMutex );
44 m_xAdapter = pAdapter;
47 OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp )
48 :m_xComponent( _rxComp )
49 ,m_pListener( nullptr )
50 ,m_bListening( false )
52 OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
56 void OComponentAdapterBase::Init( OComponentListener* _pListener )
58 OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
59 OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
61 m_pListener = _pListener;
62 if ( m_pListener )
63 m_pListener->setAdapter( this );
65 startComponentListening( );
66 m_bListening = true;
70 OComponentAdapterBase::~OComponentAdapterBase()
75 void OComponentAdapterBase::dispose()
77 if ( m_bListening )
79 ::rtl::Reference< OComponentAdapterBase > xPreventDelete(this);
81 disposing();
83 m_pListener->setAdapter(nullptr);
85 m_pListener = nullptr;
86 m_bListening = false;
88 m_xComponent = nullptr;
92 // XEventListener
95 void SAL_CALL OComponentAdapterBase::disposing( const EventObject& )
97 if ( m_pListener )
99 // disconnect the listener
100 if ( m_pListener ) // may have been reset whilest calling into _disposing
101 m_pListener->setAdapter( nullptr );
104 m_pListener = nullptr;
105 m_bListening = false;
107 m_xComponent = nullptr;
110 OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable )
111 :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ) )
116 void OLoadListenerAdapter::startComponentListening()
118 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
119 OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
120 if ( xLoadable.is() )
121 xLoadable->addLoadListener( this );
125 void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
127 OLoadListenerAdapter_Base::acquire();
131 void SAL_CALL OLoadListenerAdapter::release( ) throw ()
133 OLoadListenerAdapter_Base::release();
137 void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource )
139 OComponentAdapterBase::disposing( _rSource );
143 void OLoadListenerAdapter::disposing()
145 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
146 if ( xLoadable.is() )
147 xLoadable->removeLoadListener( this );
151 void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent )
153 if ( getLoadListener( ) )
154 getLoadListener( )->_loaded( _rEvent );
158 void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent )
160 if ( getLoadListener( ) )
161 getLoadListener( )->_unloading( _rEvent );
165 void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& _rEvent )
167 if ( getLoadListener( ) )
168 getLoadListener( )->_unloaded( _rEvent );
172 void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent )
174 if ( getLoadListener( ) )
175 getLoadListener( )->_reloading( _rEvent );
179 void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent )
181 if ( getLoadListener( ) )
182 getLoadListener( )->_reloaded( _rEvent );
186 } // namespace bib
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */