bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / bibliography / loadlisteneradapter.hxx
blobe6347cf3568f14d3819505a38894481d68b39d01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 namespace bib
33 class OComponentAdapterBase;
35 class OComponentListener
37 friend class OComponentAdapterBase;
39 private:
40 OComponentAdapterBase* m_pAdapter;
41 ::osl::Mutex& m_rMutex;
42 protected:
43 OComponentListener( ::osl::Mutex& _rMutex )
44 :m_pAdapter( NULL )
45 ,m_rMutex( _rMutex )
49 virtual ~OComponentListener();
51 protected:
52 void setAdapter( OComponentAdapterBase* _pAdapter );
55 class OComponentAdapterBase
57 friend class OComponentListener;
59 private:
60 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
61 m_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;
70 protected:
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();
81 public:
82 OComponentAdapterBase(
83 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp,
84 bool _bAutoRelease = true
87 // late construction
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;
96 // helper
97 /// get the lock count
98 sal_Int32 locked() const { return m_nLockCount; }
100 /// dispose the object - stop listening and such
101 void dispose();
103 protected:
104 // XEventListener
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;
112 protected:
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
128 protected:
129 OLoadListener* getLoadListener( ) { return static_cast< OLoadListener* >( getListener() ); }
131 protected:
132 virtual void disposing() SAL_OVERRIDE;
133 virtual void startComponentListening() SAL_OVERRIDE;
135 public:
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;
145 protected:
146 // XEventListener
147 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 // XLoadListener
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;
158 } // namespace bib
161 #endif // INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */