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 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
23 #include <osl/mutex.hxx>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <cppuhelper/implbase1.hxx>
26 #include <com/sun/star/form/XLoadable.hpp>
33 class OComponentAdapterBase
;
35 class OComponentListener
37 friend class OComponentAdapterBase
;
40 OComponentAdapterBase
* m_pAdapter
;
41 ::osl::Mutex
& m_rMutex
;
43 OComponentListener( ::osl::Mutex
& _rMutex
)
49 virtual ~OComponentListener();
52 void setAdapter( OComponentAdapterBase
* _pAdapter
);
55 class OComponentAdapterBase
57 friend class OComponentListener
;
60 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>
62 OComponentListener
* m_pListener
;
63 sal_Int32 m_nLockCount
;
64 bool m_bListening
: 1;
65 bool m_bAutoRelease
: 1;
67 // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster
68 virtual void disposing() = 0;
71 // attribute access for derivees
72 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>&
73 getComponent() const { return m_xComponent
; }
74 OComponentListener
* getListener() { return m_pListener
; }
76 // to be called by derivees which started listening at the component
77 virtual void startComponentListening() = 0;
79 virtual ~OComponentAdapterBase();
82 OComponentAdapterBase(
83 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& _rxComp
,
84 bool _bAutoRelease
= true
88 // can be called from within you ctor, to have you're object fully initialized at the moment of
89 // the call (which would not be the case when calling this ctor)
90 void Init( OComponentListener
* _pListener
);
92 // base for ref-counting, implemented by OComponentAdapter
93 virtual void SAL_CALL
acquire( ) throw () = 0;
94 virtual void SAL_CALL
release( ) throw () = 0;
97 /// get the lock count
98 sal_Int32
locked() const { return m_nLockCount
; }
100 /// dispose the object - stop listening and such
105 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
);
108 class OLoadListener
: public OComponentListener
110 friend class OLoadListenerAdapter
;
113 OLoadListener( ::osl::Mutex
& _rMutex
) : OComponentListener( _rMutex
) { }
115 // XLoadListener equivalents
116 virtual void _loaded( const ::com::sun::star::lang::EventObject
& aEvent
) = 0;
117 virtual void _unloading( const ::com::sun::star::lang::EventObject
& aEvent
) = 0;
118 virtual void _unloaded( const ::com::sun::star::lang::EventObject
& aEvent
) = 0;
119 virtual void _reloading( const ::com::sun::star::lang::EventObject
& aEvent
) = 0;
120 virtual void _reloaded( const ::com::sun::star::lang::EventObject
& aEvent
) = 0;
123 typedef ::cppu::WeakImplHelper1
< ::com::sun::star::form::XLoadListener
> OLoadListenerAdapter_Base
;
124 class OLoadListenerAdapter
125 :public OLoadListenerAdapter_Base
126 ,public OComponentAdapterBase
129 OLoadListener
* getLoadListener( ) { return static_cast< OLoadListener
* >( getListener() ); }
132 virtual void disposing() SAL_OVERRIDE
;
133 virtual void startComponentListening() SAL_OVERRIDE
;
136 OLoadListenerAdapter(
137 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XLoadable
>& _rxLoadable
,
138 bool _bAutoRelease
= true
142 virtual void SAL_CALL
acquire( ) throw () SAL_OVERRIDE
;
143 virtual void SAL_CALL
release( ) throw () SAL_OVERRIDE
;
147 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& _rSource
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
150 virtual void SAL_CALL
loaded( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
151 virtual void SAL_CALL
unloading( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
152 virtual void SAL_CALL
unloaded( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
153 virtual void SAL_CALL
reloading( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
154 virtual void SAL_CALL
reloaded( const ::com::sun::star::lang::EventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
161 #endif // INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */