Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / bibliography / loadlisteneradapter.cxx
blobdd9a7774db0b8d7499775b950f36e22011f17891
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 m_pListener->setAdapter( nullptr );
101 m_pListener = nullptr;
104 m_bListening = false;
105 m_xComponent = nullptr;
108 OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable )
109 :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ) )
114 void OLoadListenerAdapter::startComponentListening()
116 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
117 OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
118 if ( xLoadable.is() )
119 xLoadable->addLoadListener( this );
123 void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
125 OLoadListenerAdapter_Base::acquire();
129 void SAL_CALL OLoadListenerAdapter::release( ) throw ()
131 OLoadListenerAdapter_Base::release();
135 void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource )
137 OComponentAdapterBase::disposing( _rSource );
141 void OLoadListenerAdapter::disposing()
143 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
144 if ( xLoadable.is() )
145 xLoadable->removeLoadListener( this );
149 void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent )
151 if ( getLoadListener( ) )
152 getLoadListener( )->_loaded( _rEvent );
156 void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent )
158 if ( getLoadListener( ) )
159 getLoadListener( )->_unloading( _rEvent );
163 void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& )
168 void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent )
170 if ( getLoadListener( ) )
171 getLoadListener( )->_reloading( _rEvent );
175 void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent )
177 if ( getLoadListener( ) )
178 getLoadListener( )->_reloaded( _rEvent );
182 } // namespace bib
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */