Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "loadlisteneradapter.hxx"
30 : : #include <osl/diagnose.h>
31 : : #include <rtl/ref.hxx>
32 : :
33 : : //.........................................................................
34 : : namespace bib
35 : : {
36 : : //.........................................................................
37 : :
38 : : using namespace ::com::sun::star::uno;
39 : : using namespace ::com::sun::star::lang;
40 : : using namespace ::com::sun::star::form;
41 : :
42 : : //=====================================================================
43 : : //= OComponentListener
44 : : //=====================================================================
45 : : //---------------------------------------------------------------------
46 : 0 : OComponentListener::~OComponentListener()
47 : : {
48 : : {
49 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutex );
50 [ # # ]: 0 : if ( m_pAdapter )
51 [ # # ][ # # ]: 0 : m_pAdapter->dispose();
52 : : }
53 [ # # ]: 0 : }
54 : :
55 : : //---------------------------------------------------------------------
56 : 0 : void OComponentListener::_disposing( const EventObject& /*_rSource*/ ) throw( RuntimeException)
57 : : {
58 : : // nothing to do here, overrride if you're interested in
59 : 0 : }
60 : :
61 : : //---------------------------------------------------------------------
62 : 0 : void OComponentListener::setAdapter( OComponentAdapterBase* pAdapter )
63 : : {
64 : : {
65 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutex );
66 [ # # ]: 0 : if ( m_pAdapter )
67 : : {
68 : 0 : m_pAdapter->release();
69 : 0 : m_pAdapter = NULL;
70 [ # # ]: 0 : }
71 : : }
72 : :
73 [ # # ]: 0 : if ( pAdapter )
74 : : {
75 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutex );
76 : 0 : m_pAdapter = pAdapter;
77 [ # # ]: 0 : m_pAdapter->acquire();
78 : : }
79 : 0 : }
80 : :
81 : : //=====================================================================
82 : : //= OComponentAdapterBase
83 : : //=====================================================================
84 : : //---------------------------------------------------------------------
85 : 0 : OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp, sal_Bool _bAutoRelease )
86 : : :m_xComponent( _rxComp )
87 : : ,m_pListener( NULL )
88 : : ,m_nLockCount( 0 )
89 : : ,m_bListening( sal_False )
90 : 0 : ,m_bAutoRelease( _bAutoRelease )
91 : : {
92 : : OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
93 : 0 : }
94 : :
95 : : //---------------------------------------------------------------------
96 : 0 : void OComponentAdapterBase::Init( OComponentListener* _pListener )
97 : : {
98 : : OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
99 : : OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
100 : :
101 : 0 : m_pListener = _pListener;
102 [ # # ]: 0 : if ( m_pListener )
103 : 0 : m_pListener->setAdapter( this );
104 : :
105 : 0 : startComponentListening( );
106 : 0 : m_bListening = sal_True;
107 : 0 : }
108 : :
109 : : //---------------------------------------------------------------------
110 : 0 : OComponentAdapterBase::~OComponentAdapterBase()
111 : : {
112 [ # # ]: 0 : }
113 : :
114 : : //---------------------------------------------------------------------
115 : 0 : void OComponentAdapterBase::dispose()
116 : : {
117 [ # # ]: 0 : if ( m_bListening )
118 : : {
119 : 0 : ::rtl::Reference< OComponentAdapterBase > xPreventDelete(this);
120 : :
121 [ # # ]: 0 : disposing();
122 : :
123 [ # # ]: 0 : m_pListener->setAdapter(NULL);
124 : :
125 : 0 : m_pListener = NULL;
126 : 0 : m_bListening = sal_False;
127 : :
128 [ # # ]: 0 : if (m_bAutoRelease)
129 [ # # ]: 0 : m_xComponent = NULL;
130 : : }
131 : 0 : }
132 : :
133 : : // XEventListener
134 : :
135 : : //---------------------------------------------------------------------
136 : 0 : void SAL_CALL OComponentAdapterBase::disposing( const EventObject& _rSource ) throw( RuntimeException )
137 : : {
138 [ # # ]: 0 : if ( m_pListener )
139 : : {
140 : : // tell the listener
141 [ # # ]: 0 : if ( !locked() )
142 : 0 : m_pListener->_disposing( _rSource );
143 : :
144 : : // disconnect the listener
145 [ # # ]: 0 : if ( m_pListener ) // may have been reset whilest calling into _disposing
146 : 0 : m_pListener->setAdapter( NULL );
147 : : }
148 : :
149 : 0 : m_pListener = NULL;
150 : 0 : m_bListening = sal_False;
151 : :
152 [ # # ]: 0 : if ( m_bAutoRelease )
153 : 0 : m_xComponent = NULL;
154 : 0 : }
155 : :
156 : : //=====================================================================
157 : : //= OLoadListenerAdapter
158 : : //=====================================================================
159 : : //---------------------------------------------------------------------
160 : 0 : OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable, sal_Bool _bAutoRelease )
161 [ # # ][ # # ]: 0 : :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ), _bAutoRelease )
162 : : {
163 : 0 : }
164 : :
165 : : //---------------------------------------------------------------------
166 : 0 : void OLoadListenerAdapter::startComponentListening()
167 : : {
168 [ # # ]: 0 : Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
169 : : OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
170 [ # # ]: 0 : if ( xLoadable.is() )
171 [ # # ][ # # ]: 0 : xLoadable->addLoadListener( this );
[ # # ]
172 : 0 : }
173 : :
174 : : //---------------------------------------------------------------------
175 : 0 : void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
176 : : {
177 : 0 : OLoadListenerAdapter_Base::acquire();
178 : 0 : }
179 : :
180 : : //---------------------------------------------------------------------
181 : 0 : void SAL_CALL OLoadListenerAdapter::release( ) throw ()
182 : : {
183 : 0 : OLoadListenerAdapter_Base::release();
184 : 0 : }
185 : :
186 : : //---------------------------------------------------------------------
187 : 0 : void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource ) throw( RuntimeException)
188 : : {
189 : 0 : OComponentAdapterBase::disposing( _rSource );
190 : 0 : }
191 : :
192 : : //---------------------------------------------------------------------
193 : 0 : void OLoadListenerAdapter::disposing()
194 : : {
195 [ # # ]: 0 : Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
196 [ # # ]: 0 : if ( xLoadable.is() )
197 [ # # ][ # # ]: 0 : xLoadable->removeLoadListener( this );
[ # # ]
198 : 0 : }
199 : :
200 : : //---------------------------------------------------------------------
201 : 0 : void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent ) throw (RuntimeException)
202 : : {
203 [ # # ][ # # ]: 0 : if ( !locked() && getLoadListener( ) )
[ # # ]
204 : 0 : getLoadListener( )->_loaded( _rEvent );
205 : 0 : }
206 : :
207 : : //---------------------------------------------------------------------
208 : 0 : void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent ) throw (RuntimeException)
209 : : {
210 [ # # ][ # # ]: 0 : if ( !locked() && getLoadListener( ) )
[ # # ]
211 : 0 : getLoadListener( )->_unloading( _rEvent );
212 : 0 : }
213 : :
214 : : //---------------------------------------------------------------------
215 : 0 : void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& _rEvent ) throw (RuntimeException)
216 : : {
217 [ # # ][ # # ]: 0 : if ( !locked() && getLoadListener( ) )
[ # # ]
218 : 0 : getLoadListener( )->_unloaded( _rEvent );
219 : 0 : }
220 : :
221 : : //---------------------------------------------------------------------
222 : 0 : void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent ) throw (RuntimeException)
223 : : {
224 [ # # ][ # # ]: 0 : if ( !locked() && getLoadListener( ) )
[ # # ]
225 : 0 : getLoadListener( )->_reloading( _rEvent );
226 : 0 : }
227 : :
228 : : //---------------------------------------------------------------------
229 : 0 : void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent ) throw (RuntimeException)
230 : : {
231 [ # # ][ # # ]: 0 : if ( !locked() && getLoadListener( ) )
[ # # ]
232 : 0 : getLoadListener( )->_reloaded( _rEvent );
233 : 0 : }
234 : :
235 : : //.........................................................................
236 : : } // namespace bib
237 : : //.........................................................................
238 : :
239 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|