Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "loadlisteneradapter.hxx"
21 : #include <osl/diagnose.h>
22 : #include <rtl/ref.hxx>
23 :
24 :
25 : namespace bib
26 : {
27 :
28 :
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::lang;
31 : using namespace ::com::sun::star::form;
32 :
33 :
34 : //= OComponentListener
35 :
36 :
37 0 : OComponentListener::~OComponentListener()
38 : {
39 : {
40 0 : ::osl::MutexGuard aGuard( m_rMutex );
41 0 : if ( m_pAdapter )
42 0 : m_pAdapter->dispose();
43 : }
44 0 : }
45 :
46 :
47 0 : void OComponentListener::_disposing( const EventObject& /*_rSource*/ ) throw( RuntimeException)
48 : {
49 : // nothing to do here, override if you're interested in
50 0 : }
51 :
52 :
53 0 : void OComponentListener::setAdapter( OComponentAdapterBase* pAdapter )
54 : {
55 : {
56 0 : ::osl::MutexGuard aGuard( m_rMutex );
57 0 : if ( m_pAdapter )
58 : {
59 0 : m_pAdapter->release();
60 0 : m_pAdapter = NULL;
61 0 : }
62 : }
63 :
64 0 : if ( pAdapter )
65 : {
66 0 : ::osl::MutexGuard aGuard( m_rMutex );
67 0 : m_pAdapter = pAdapter;
68 0 : m_pAdapter->acquire();
69 : }
70 0 : }
71 :
72 :
73 : //= OComponentAdapterBase
74 :
75 :
76 0 : OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp, sal_Bool _bAutoRelease )
77 : :m_xComponent( _rxComp )
78 : ,m_pListener( NULL )
79 : ,m_nLockCount( 0 )
80 : ,m_bListening( sal_False )
81 0 : ,m_bAutoRelease( _bAutoRelease )
82 : {
83 : OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
84 0 : }
85 :
86 :
87 0 : void OComponentAdapterBase::Init( OComponentListener* _pListener )
88 : {
89 : OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
90 : OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
91 :
92 0 : m_pListener = _pListener;
93 0 : if ( m_pListener )
94 0 : m_pListener->setAdapter( this );
95 :
96 0 : startComponentListening( );
97 0 : m_bListening = sal_True;
98 0 : }
99 :
100 :
101 0 : OComponentAdapterBase::~OComponentAdapterBase()
102 : {
103 0 : }
104 :
105 :
106 0 : void OComponentAdapterBase::dispose()
107 : {
108 0 : if ( m_bListening )
109 : {
110 0 : ::rtl::Reference< OComponentAdapterBase > xPreventDelete(this);
111 :
112 0 : disposing();
113 :
114 0 : m_pListener->setAdapter(NULL);
115 :
116 0 : m_pListener = NULL;
117 0 : m_bListening = sal_False;
118 :
119 0 : if (m_bAutoRelease)
120 0 : m_xComponent = NULL;
121 : }
122 0 : }
123 :
124 : // XEventListener
125 :
126 :
127 0 : void SAL_CALL OComponentAdapterBase::disposing( const EventObject& _rSource ) throw( RuntimeException, std::exception )
128 : {
129 0 : if ( m_pListener )
130 : {
131 : // tell the listener
132 0 : if ( !locked() )
133 0 : m_pListener->_disposing( _rSource );
134 :
135 : // disconnect the listener
136 0 : if ( m_pListener ) // may have been reset whilest calling into _disposing
137 0 : m_pListener->setAdapter( NULL );
138 : }
139 :
140 0 : m_pListener = NULL;
141 0 : m_bListening = sal_False;
142 :
143 0 : if ( m_bAutoRelease )
144 0 : m_xComponent = NULL;
145 0 : }
146 :
147 :
148 : //= OLoadListenerAdapter
149 :
150 :
151 0 : OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable, sal_Bool _bAutoRelease )
152 0 : :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ), _bAutoRelease )
153 : {
154 0 : }
155 :
156 :
157 0 : void OLoadListenerAdapter::startComponentListening()
158 : {
159 0 : Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
160 : OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
161 0 : if ( xLoadable.is() )
162 0 : xLoadable->addLoadListener( this );
163 0 : }
164 :
165 :
166 0 : void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
167 : {
168 0 : OLoadListenerAdapter_Base::acquire();
169 0 : }
170 :
171 :
172 0 : void SAL_CALL OLoadListenerAdapter::release( ) throw ()
173 : {
174 0 : OLoadListenerAdapter_Base::release();
175 0 : }
176 :
177 :
178 0 : void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource ) throw( RuntimeException, std::exception)
179 : {
180 0 : OComponentAdapterBase::disposing( _rSource );
181 0 : }
182 :
183 :
184 0 : void OLoadListenerAdapter::disposing()
185 : {
186 0 : Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
187 0 : if ( xLoadable.is() )
188 0 : xLoadable->removeLoadListener( this );
189 0 : }
190 :
191 :
192 0 : void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
193 : {
194 0 : if ( !locked() && getLoadListener( ) )
195 0 : getLoadListener( )->_loaded( _rEvent );
196 0 : }
197 :
198 :
199 0 : void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
200 : {
201 0 : if ( !locked() && getLoadListener( ) )
202 0 : getLoadListener( )->_unloading( _rEvent );
203 0 : }
204 :
205 :
206 0 : void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
207 : {
208 0 : if ( !locked() && getLoadListener( ) )
209 0 : getLoadListener( )->_unloaded( _rEvent );
210 0 : }
211 :
212 :
213 0 : void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
214 : {
215 0 : if ( !locked() && getLoadListener( ) )
216 0 : getLoadListener( )->_reloading( _rEvent );
217 0 : }
218 :
219 :
220 0 : void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
221 : {
222 0 : if ( !locked() && getLoadListener( ) )
223 0 : getLoadListener( )->_reloaded( _rEvent );
224 0 : }
225 :
226 :
227 : } // namespace bib
228 :
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|