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 0 : OComponentListener::~OComponentListener()
34 : {
35 : {
36 0 : ::osl::MutexGuard aGuard( m_rMutex );
37 0 : if ( m_pAdapter )
38 0 : m_pAdapter->dispose();
39 : }
40 0 : }
41 :
42 :
43 0 : void OComponentListener::setAdapter( OComponentAdapterBase* pAdapter )
44 : {
45 : {
46 0 : ::osl::MutexGuard aGuard( m_rMutex );
47 0 : if ( m_pAdapter )
48 : {
49 0 : m_pAdapter->release();
50 0 : m_pAdapter = NULL;
51 0 : }
52 : }
53 :
54 0 : if ( pAdapter )
55 : {
56 0 : ::osl::MutexGuard aGuard( m_rMutex );
57 0 : m_pAdapter = pAdapter;
58 0 : m_pAdapter->acquire();
59 : }
60 0 : }
61 :
62 0 : OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp, bool _bAutoRelease )
63 : :m_xComponent( _rxComp )
64 : ,m_pListener( NULL )
65 : ,m_nLockCount( 0 )
66 : ,m_bListening( false )
67 0 : ,m_bAutoRelease( _bAutoRelease )
68 : {
69 : OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
70 0 : }
71 :
72 :
73 0 : void OComponentAdapterBase::Init( OComponentListener* _pListener )
74 : {
75 : OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
76 : OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
77 :
78 0 : m_pListener = _pListener;
79 0 : if ( m_pListener )
80 0 : m_pListener->setAdapter( this );
81 :
82 0 : startComponentListening( );
83 0 : m_bListening = true;
84 0 : }
85 :
86 :
87 0 : OComponentAdapterBase::~OComponentAdapterBase()
88 : {
89 0 : }
90 :
91 :
92 0 : void OComponentAdapterBase::dispose()
93 : {
94 0 : if ( m_bListening )
95 : {
96 0 : ::rtl::Reference< OComponentAdapterBase > xPreventDelete(this);
97 :
98 0 : disposing();
99 :
100 0 : m_pListener->setAdapter(NULL);
101 :
102 0 : m_pListener = NULL;
103 0 : m_bListening = false;
104 :
105 0 : if (m_bAutoRelease)
106 0 : m_xComponent = NULL;
107 : }
108 0 : }
109 :
110 : // XEventListener
111 :
112 :
113 0 : void SAL_CALL OComponentAdapterBase::disposing( const EventObject& ) throw( RuntimeException, std::exception )
114 : {
115 0 : if ( m_pListener )
116 : {
117 : // disconnect the listener
118 0 : if ( m_pListener ) // may have been reset whilest calling into _disposing
119 0 : m_pListener->setAdapter( NULL );
120 : }
121 :
122 0 : m_pListener = NULL;
123 0 : m_bListening = false;
124 :
125 0 : if ( m_bAutoRelease )
126 0 : m_xComponent = NULL;
127 0 : }
128 :
129 0 : OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable, bool _bAutoRelease )
130 0 : :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ), _bAutoRelease )
131 : {
132 0 : }
133 :
134 :
135 0 : void OLoadListenerAdapter::startComponentListening()
136 : {
137 0 : Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
138 : OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
139 0 : if ( xLoadable.is() )
140 0 : xLoadable->addLoadListener( this );
141 0 : }
142 :
143 :
144 0 : void SAL_CALL OLoadListenerAdapter::acquire( ) throw ()
145 : {
146 0 : OLoadListenerAdapter_Base::acquire();
147 0 : }
148 :
149 :
150 0 : void SAL_CALL OLoadListenerAdapter::release( ) throw ()
151 : {
152 0 : OLoadListenerAdapter_Base::release();
153 0 : }
154 :
155 :
156 0 : void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource ) throw( RuntimeException, std::exception)
157 : {
158 0 : OComponentAdapterBase::disposing( _rSource );
159 0 : }
160 :
161 :
162 0 : void OLoadListenerAdapter::disposing()
163 : {
164 0 : Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
165 0 : if ( xLoadable.is() )
166 0 : xLoadable->removeLoadListener( this );
167 0 : }
168 :
169 :
170 0 : void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
171 : {
172 0 : if ( !locked() && getLoadListener( ) )
173 0 : getLoadListener( )->_loaded( _rEvent );
174 0 : }
175 :
176 :
177 0 : void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
178 : {
179 0 : if ( !locked() && getLoadListener( ) )
180 0 : getLoadListener( )->_unloading( _rEvent );
181 0 : }
182 :
183 :
184 0 : void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
185 : {
186 0 : if ( !locked() && getLoadListener( ) )
187 0 : getLoadListener( )->_unloaded( _rEvent );
188 0 : }
189 :
190 :
191 0 : void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
192 : {
193 0 : if ( !locked() && getLoadListener( ) )
194 0 : getLoadListener( )->_reloading( _rEvent );
195 0 : }
196 :
197 :
198 0 : void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent ) throw (RuntimeException, std::exception)
199 : {
200 0 : if ( !locked() && getLoadListener( ) )
201 0 : getLoadListener( )->_reloaded( _rEvent );
202 0 : }
203 :
204 :
205 : } // namespace bib
206 :
207 :
208 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|