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 .
22 #include <osl/mutex.hxx>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <cppuhelper/implbase.hxx>
25 #include <com/sun/star/form/XLoadable.hpp>
26 #include <rtl/ref.hxx>
33 class OComponentAdapterBase
;
35 class OComponentListener
37 friend class OComponentAdapterBase
;
40 rtl::Reference
<OComponentAdapterBase
> m_xAdapter
;
41 ::osl::Mutex
& m_rMutex
;
43 explicit OComponentListener( ::osl::Mutex
& _rMutex
)
48 virtual ~OComponentListener();
51 void setAdapter( OComponentAdapterBase
* _pAdapter
);
54 class OComponentAdapterBase
56 friend class OComponentListener
;
59 css::uno::Reference
< css::lang::XComponent
> m_xComponent
;
60 OComponentListener
* m_pListener
;
61 bool m_bListening
: 1;
63 // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster
64 virtual void disposing() = 0;
67 // attribute access for derivees
68 const css::uno::Reference
< css::lang::XComponent
>&
69 getComponent() const { return m_xComponent
; }
70 OComponentListener
* getListener() { return m_pListener
; }
72 // to be called by derivees which started listening at the component
73 virtual void startComponentListening() = 0;
75 virtual ~OComponentAdapterBase();
78 explicit OComponentAdapterBase(
79 const css::uno::Reference
< css::lang::XComponent
>& _rxComp
83 // can be called from within you ctor, to have you're object fully initialized at the moment of
84 // the call (which would not be the case when calling this ctor)
85 void Init( OComponentListener
* _pListener
);
87 // base for ref-counting, implemented by OComponentAdapter
88 virtual void SAL_CALL
acquire( ) noexcept
= 0;
89 virtual void SAL_CALL
release( ) noexcept
= 0;
91 /// dispose the object - stop listening and such
96 /// @throws css::uno::RuntimeException
97 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
);
100 class OLoadListener
: public OComponentListener
102 friend class OLoadListenerAdapter
;
105 explicit OLoadListener( ::osl::Mutex
& _rMutex
) : OComponentListener( _rMutex
) { }
107 // XLoadListener equivalents
108 virtual void _loaded( const css::lang::EventObject
& aEvent
) = 0;
109 virtual void _unloading( const css::lang::EventObject
& aEvent
) = 0;
110 virtual void _reloading( const css::lang::EventObject
& aEvent
) = 0;
111 virtual void _reloaded( const css::lang::EventObject
& aEvent
) = 0;
114 typedef ::cppu::WeakImplHelper
< css::form::XLoadListener
> OLoadListenerAdapter_Base
;
115 class OLoadListenerAdapter
116 :public OLoadListenerAdapter_Base
117 ,public OComponentAdapterBase
120 OLoadListener
* getLoadListener( ) { return static_cast< OLoadListener
* >( getListener() ); }
123 virtual void disposing() override
;
124 virtual void startComponentListening() override
;
127 explicit OLoadListenerAdapter(
128 const css::uno::Reference
< css::form::XLoadable
>& _rxLoadable
132 virtual void SAL_CALL
acquire( ) noexcept override
;
133 virtual void SAL_CALL
release( ) noexcept override
;
137 virtual void SAL_CALL
disposing( const css::lang::EventObject
& _rSource
) override
;
140 virtual void SAL_CALL
loaded( const css::lang::EventObject
& aEvent
) override
;
141 virtual void SAL_CALL
unloading( const css::lang::EventObject
& aEvent
) override
;
142 virtual void SAL_CALL
unloaded( const css::lang::EventObject
& aEvent
) override
;
143 virtual void SAL_CALL
reloading( const css::lang::EventObject
& aEvent
) override
;
144 virtual void SAL_CALL
reloaded( const css::lang::EventObject
& aEvent
) override
;
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */