1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::lang
;
31 using namespace ::com::sun::star::form
;
33 OComponentListener::~OComponentListener()
36 ::osl::MutexGuard
aGuard( m_rMutex
);
38 m_pAdapter
->dispose();
43 void OComponentListener::setAdapter( OComponentAdapterBase
* pAdapter
)
46 ::osl::MutexGuard
aGuard( m_rMutex
);
49 m_pAdapter
->release();
56 ::osl::MutexGuard
aGuard( m_rMutex
);
57 m_pAdapter
= pAdapter
;
58 m_pAdapter
->acquire();
62 OComponentAdapterBase::OComponentAdapterBase( const Reference
< XComponent
>& _rxComp
, bool _bAutoRelease
)
63 :m_xComponent( _rxComp
)
66 ,m_bListening( false )
67 ,m_bAutoRelease( _bAutoRelease
)
69 OSL_ENSURE( m_xComponent
.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
73 void OComponentAdapterBase::Init( OComponentListener
* _pListener
)
75 OSL_ENSURE( !m_pListener
, "OComponentAdapterBase::Init: already initialized!" );
76 OSL_ENSURE( _pListener
, "OComponentAdapterBase::Init: invalid listener!" );
78 m_pListener
= _pListener
;
80 m_pListener
->setAdapter( this );
82 startComponentListening( );
87 OComponentAdapterBase::~OComponentAdapterBase()
92 void OComponentAdapterBase::dispose()
96 ::rtl::Reference
< OComponentAdapterBase
> xPreventDelete(this);
100 m_pListener
->setAdapter(NULL
);
103 m_bListening
= false;
113 void SAL_CALL
OComponentAdapterBase::disposing( const EventObject
& ) throw( RuntimeException
, std::exception
)
117 // disconnect the listener
118 if ( m_pListener
) // may have been reset whilest calling into _disposing
119 m_pListener
->setAdapter( NULL
);
123 m_bListening
= false;
125 if ( m_bAutoRelease
)
129 OLoadListenerAdapter::OLoadListenerAdapter( const Reference
< XLoadable
>& _rxLoadable
, bool _bAutoRelease
)
130 :OComponentAdapterBase( Reference
< XComponent
>( _rxLoadable
, UNO_QUERY
), _bAutoRelease
)
135 void OLoadListenerAdapter::startComponentListening()
137 Reference
< XLoadable
> xLoadable( getComponent(), UNO_QUERY
);
138 OSL_ENSURE( xLoadable
.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
139 if ( xLoadable
.is() )
140 xLoadable
->addLoadListener( this );
144 void SAL_CALL
OLoadListenerAdapter::acquire( ) throw ()
146 OLoadListenerAdapter_Base::acquire();
150 void SAL_CALL
OLoadListenerAdapter::release( ) throw ()
152 OLoadListenerAdapter_Base::release();
156 void SAL_CALL
OLoadListenerAdapter::disposing( const EventObject
& _rSource
) throw( RuntimeException
, std::exception
)
158 OComponentAdapterBase::disposing( _rSource
);
162 void OLoadListenerAdapter::disposing()
164 Reference
< XLoadable
> xLoadable( getComponent(), UNO_QUERY
);
165 if ( xLoadable
.is() )
166 xLoadable
->removeLoadListener( this );
170 void SAL_CALL
OLoadListenerAdapter::loaded( const EventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
172 if ( !locked() && getLoadListener( ) )
173 getLoadListener( )->_loaded( _rEvent
);
177 void SAL_CALL
OLoadListenerAdapter::unloading( const EventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
179 if ( !locked() && getLoadListener( ) )
180 getLoadListener( )->_unloading( _rEvent
);
184 void SAL_CALL
OLoadListenerAdapter::unloaded( const EventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
186 if ( !locked() && getLoadListener( ) )
187 getLoadListener( )->_unloaded( _rEvent
);
191 void SAL_CALL
OLoadListenerAdapter::reloading( const EventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
193 if ( !locked() && getLoadListener( ) )
194 getLoadListener( )->_reloading( _rEvent
);
198 void SAL_CALL
OLoadListenerAdapter::reloaded( const EventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
200 if ( !locked() && getLoadListener( ) )
201 getLoadListener( )->_reloaded( _rEvent
);
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */