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>
24 //.........................................................................
27 //.........................................................................
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::lang
;
31 using namespace ::com::sun::star::form
;
33 //=====================================================================
34 //= OComponentListener
35 //=====================================================================
36 //---------------------------------------------------------------------
37 OComponentListener::~OComponentListener()
40 ::osl::MutexGuard
aGuard( m_rMutex
);
42 m_pAdapter
->dispose();
46 //---------------------------------------------------------------------
47 void OComponentListener::_disposing( const EventObject
& /*_rSource*/ ) throw( RuntimeException
)
49 // nothing to do here, overrride if you're interested in
52 //---------------------------------------------------------------------
53 void OComponentListener::setAdapter( OComponentAdapterBase
* pAdapter
)
56 ::osl::MutexGuard
aGuard( m_rMutex
);
59 m_pAdapter
->release();
66 ::osl::MutexGuard
aGuard( m_rMutex
);
67 m_pAdapter
= pAdapter
;
68 m_pAdapter
->acquire();
72 //=====================================================================
73 //= OComponentAdapterBase
74 //=====================================================================
75 //---------------------------------------------------------------------
76 OComponentAdapterBase::OComponentAdapterBase( const Reference
< XComponent
>& _rxComp
, sal_Bool _bAutoRelease
)
77 :m_xComponent( _rxComp
)
80 ,m_bListening( sal_False
)
81 ,m_bAutoRelease( _bAutoRelease
)
83 OSL_ENSURE( m_xComponent
.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
86 //---------------------------------------------------------------------
87 void OComponentAdapterBase::Init( OComponentListener
* _pListener
)
89 OSL_ENSURE( !m_pListener
, "OComponentAdapterBase::Init: already initialized!" );
90 OSL_ENSURE( _pListener
, "OComponentAdapterBase::Init: invalid listener!" );
92 m_pListener
= _pListener
;
94 m_pListener
->setAdapter( this );
96 startComponentListening( );
97 m_bListening
= sal_True
;
100 //---------------------------------------------------------------------
101 OComponentAdapterBase::~OComponentAdapterBase()
105 //---------------------------------------------------------------------
106 void OComponentAdapterBase::dispose()
110 ::rtl::Reference
< OComponentAdapterBase
> xPreventDelete(this);
114 m_pListener
->setAdapter(NULL
);
117 m_bListening
= sal_False
;
126 //---------------------------------------------------------------------
127 void SAL_CALL
OComponentAdapterBase::disposing( const EventObject
& _rSource
) throw( RuntimeException
)
133 m_pListener
->_disposing( _rSource
);
135 // disconnect the listener
136 if ( m_pListener
) // may have been reset whilest calling into _disposing
137 m_pListener
->setAdapter( NULL
);
141 m_bListening
= sal_False
;
143 if ( m_bAutoRelease
)
147 //=====================================================================
148 //= OLoadListenerAdapter
149 //=====================================================================
150 //---------------------------------------------------------------------
151 OLoadListenerAdapter::OLoadListenerAdapter( const Reference
< XLoadable
>& _rxLoadable
, sal_Bool _bAutoRelease
)
152 :OComponentAdapterBase( Reference
< XComponent
>( _rxLoadable
, UNO_QUERY
), _bAutoRelease
)
156 //---------------------------------------------------------------------
157 void OLoadListenerAdapter::startComponentListening()
159 Reference
< XLoadable
> xLoadable( getComponent(), UNO_QUERY
);
160 OSL_ENSURE( xLoadable
.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
161 if ( xLoadable
.is() )
162 xLoadable
->addLoadListener( this );
165 //---------------------------------------------------------------------
166 void SAL_CALL
OLoadListenerAdapter::acquire( ) throw ()
168 OLoadListenerAdapter_Base::acquire();
171 //---------------------------------------------------------------------
172 void SAL_CALL
OLoadListenerAdapter::release( ) throw ()
174 OLoadListenerAdapter_Base::release();
177 //---------------------------------------------------------------------
178 void SAL_CALL
OLoadListenerAdapter::disposing( const EventObject
& _rSource
) throw( RuntimeException
)
180 OComponentAdapterBase::disposing( _rSource
);
183 //---------------------------------------------------------------------
184 void OLoadListenerAdapter::disposing()
186 Reference
< XLoadable
> xLoadable( getComponent(), UNO_QUERY
);
187 if ( xLoadable
.is() )
188 xLoadable
->removeLoadListener( this );
191 //---------------------------------------------------------------------
192 void SAL_CALL
OLoadListenerAdapter::loaded( const EventObject
& _rEvent
) throw (RuntimeException
)
194 if ( !locked() && getLoadListener( ) )
195 getLoadListener( )->_loaded( _rEvent
);
198 //---------------------------------------------------------------------
199 void SAL_CALL
OLoadListenerAdapter::unloading( const EventObject
& _rEvent
) throw (RuntimeException
)
201 if ( !locked() && getLoadListener( ) )
202 getLoadListener( )->_unloading( _rEvent
);
205 //---------------------------------------------------------------------
206 void SAL_CALL
OLoadListenerAdapter::unloaded( const EventObject
& _rEvent
) throw (RuntimeException
)
208 if ( !locked() && getLoadListener( ) )
209 getLoadListener( )->_unloaded( _rEvent
);
212 //---------------------------------------------------------------------
213 void SAL_CALL
OLoadListenerAdapter::reloading( const EventObject
& _rEvent
) throw (RuntimeException
)
215 if ( !locked() && getLoadListener( ) )
216 getLoadListener( )->_reloading( _rEvent
);
219 //---------------------------------------------------------------------
220 void SAL_CALL
OLoadListenerAdapter::reloaded( const EventObject
& _rEvent
) throw (RuntimeException
)
222 if ( !locked() && getLoadListener( ) )
223 getLoadListener( )->_reloaded( _rEvent
);
226 //.........................................................................
228 //.........................................................................
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */