LibreOffice Module extensions (master) 1
loadlisteneradapter.cxx
Go to the documentation of this file.
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
21#include <osl/diagnose.h>
22#include <rtl/ref.hxx>
23
24
25namespace 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
34 {
35 ::osl::MutexGuard aGuard( m_rMutex );
36 if ( m_xAdapter.is() )
37 m_xAdapter->dispose();
38 }
39
40
42 {
43 ::osl::MutexGuard aGuard( m_rMutex );
44 m_xAdapter = pAdapter;
45 }
46
47 OComponentAdapterBase::OComponentAdapterBase( const Reference< XComponent >& _rxComp )
48 :m_xComponent( _rxComp )
49 ,m_pListener( nullptr )
50 ,m_bListening( false )
51 {
52 OSL_ENSURE( m_xComponent.is(), "OComponentAdapterBase::OComponentAdapterBase: invalid component!" );
53 }
54
55
57 {
58 OSL_ENSURE( !m_pListener, "OComponentAdapterBase::Init: already initialized!" );
59 OSL_ENSURE( _pListener, "OComponentAdapterBase::Init: invalid listener!" );
60
61 m_pListener = _pListener;
62 if ( m_pListener )
63 m_pListener->setAdapter( this );
64
66 m_bListening = true;
67 }
68
69
71 {
72 }
73
74
76 {
77 if ( !m_bListening )
78 return;
79
81
82 disposing();
83
84 m_pListener->setAdapter(nullptr);
85
86 m_pListener = nullptr;
87 m_bListening = false;
88
89 m_xComponent = nullptr;
90 }
91
92 // XEventListener
93
94
95 void SAL_CALL OComponentAdapterBase::disposing( const EventObject& )
96 {
97 if (m_pListener)
98 {
99 // disconnect the listener
100 m_pListener->setAdapter( nullptr );
101 m_pListener = nullptr;
102 }
103
104 m_bListening = false;
105 m_xComponent = nullptr;
106 }
107
108 OLoadListenerAdapter::OLoadListenerAdapter( const Reference< XLoadable >& _rxLoadable )
109 :OComponentAdapterBase( Reference< XComponent >( _rxLoadable, UNO_QUERY ) )
110 {
111 }
112
113
115 {
116 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
117 OSL_ENSURE( xLoadable.is(), "OLoadListenerAdapter::OLoadListenerAdapter: invalid object!" );
118 if ( xLoadable.is() )
119 xLoadable->addLoadListener( this );
120 }
121
122
123 void SAL_CALL OLoadListenerAdapter::acquire( ) noexcept
124 {
125 OLoadListenerAdapter_Base::acquire();
126 }
127
128
129 void SAL_CALL OLoadListenerAdapter::release( ) noexcept
130 {
131 OLoadListenerAdapter_Base::release();
132 }
133
134
135 void SAL_CALL OLoadListenerAdapter::disposing( const EventObject& _rSource )
136 {
138 }
139
140
142 {
143 Reference< XLoadable > xLoadable( getComponent(), UNO_QUERY );
144 if ( xLoadable.is() )
145 xLoadable->removeLoadListener( this );
146 }
147
148
149 void SAL_CALL OLoadListenerAdapter::loaded( const EventObject& _rEvent )
150 {
151 if ( getLoadListener( ) )
152 getLoadListener( )->_loaded( _rEvent );
153 }
154
155
156 void SAL_CALL OLoadListenerAdapter::unloading( const EventObject& _rEvent )
157 {
158 if ( getLoadListener( ) )
159 getLoadListener( )->_unloading( _rEvent );
160 }
161
162
163 void SAL_CALL OLoadListenerAdapter::unloaded( const EventObject& )
164 {
165 }
166
167
168 void SAL_CALL OLoadListenerAdapter::reloading( const EventObject& _rEvent )
169 {
170 if ( getLoadListener( ) )
171 getLoadListener( )->_reloading( _rEvent );
172 }
173
174
175 void SAL_CALL OLoadListenerAdapter::reloaded( const EventObject& _rEvent )
176 {
177 if ( getLoadListener( ) )
178 getLoadListener( )->_reloaded( _rEvent );
179 }
180
181
182} // namespace bib
183
184
185/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Init(OComponentListener *_pListener)
virtual void startComponentListening()=0
void dispose()
dispose the object - stop listening and such
virtual void disposing()=0
OComponentAdapterBase(const css::uno::Reference< css::lang::XComponent > &_rxComp)
const css::uno::Reference< css::lang::XComponent > & getComponent() const
OComponentListener * m_pListener
css::uno::Reference< css::lang::XComponent > m_xComponent
void setAdapter(OComponentAdapterBase *_pAdapter)
rtl::Reference< OComponentAdapterBase > m_xAdapter
virtual void SAL_CALL unloading(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL loaded(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL acquire() noexcept override
OLoadListenerAdapter(const css::uno::Reference< css::form::XLoadable > &_rxLoadable)
virtual void SAL_CALL reloading(const css::lang::EventObject &aEvent) override
virtual void startComponentListening() override
virtual void disposing() override
virtual void SAL_CALL reloaded(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL unloaded(const css::lang::EventObject &aEvent) override
virtual void _reloaded(const css::lang::EventObject &aEvent)=0
virtual void _reloading(const css::lang::EventObject &aEvent)=0
virtual void _unloading(const css::lang::EventObject &aEvent)=0
virtual void _loaded(const css::lang::EventObject &aEvent)=0
Definition: bibbeam.cxx:40
Reference