merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / bibliography / loadlisteneradapter.hxx
blobf0a0cf1e5a3ebacb7c9f2d51450d2740901791cb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX
29 #define EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX
31 #include <osl/mutex.hxx>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <cppuhelper/implbase1.hxx>
34 #include <com/sun/star/form/XLoadable.hpp>
36 //.........................................................................
37 namespace bib
39 //.........................................................................
41 class OComponentAdapterBase;
43 //=====================================================================
44 //= OComponentListener
45 //=====================================================================
46 class OComponentListener
48 friend class OComponentAdapterBase;
50 private:
51 OComponentAdapterBase* m_pAdapter;
52 ::osl::Mutex& m_rMutex;
53 protected:
54 OComponentListener( ::osl::Mutex& _rMutex )
55 :m_pAdapter( NULL )
56 ,m_rMutex( _rMutex )
60 virtual ~OComponentListener();
62 // XEventListener equivalents
63 virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException );
65 protected:
66 void setAdapter( OComponentAdapterBase* _pAdapter );
69 //=====================================================================
70 //= OComponentAdapterBase
71 //=====================================================================
72 class OComponentAdapterBase
74 friend class OComponentListener;
76 private:
77 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
78 m_xComponent;
79 OComponentListener* m_pListener;
80 sal_Int32 m_nLockCount;
81 sal_Bool m_bListening : 1;
82 sal_Bool m_bAutoRelease : 1;
84 // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster
85 virtual void disposing() = 0;
87 protected:
88 // attribute access for derivees
89 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >&
90 getComponent() const { return m_xComponent; }
91 OComponentListener* getListener() { return m_pListener; }
93 // to be called by derivees which started listening at the component
94 virtual void startComponentListening() = 0;
96 virtual ~OComponentAdapterBase();
98 public:
99 OComponentAdapterBase(
100 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp,
101 sal_Bool _bAutoRelease = sal_True
104 // late construction
105 // can be called from within you ctor, to have you're object fully initialized at the moment of
106 // the call (which would not be the case when calling this ctor)
107 void Init( OComponentListener* _pListener );
109 // base for ref-counting, implemented by OComponentAdapter
110 virtual void SAL_CALL acquire( ) throw () = 0;
111 virtual void SAL_CALL release( ) throw () = 0;
113 // helper
114 /// get the lock count
115 sal_Int32 locked() const { return m_nLockCount; }
117 /// dispose the object - stop listening and such
118 void dispose();
120 protected:
121 // XEventListener
122 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
125 //=====================================================================
126 //= OLoadListener
127 //=====================================================================
128 class OLoadListener : public OComponentListener
130 friend class OLoadListenerAdapter;
132 protected:
133 OLoadListener( ::osl::Mutex& _rMutex ) : OComponentListener( _rMutex ) { }
135 // XLoadListener equivalents
136 virtual void _loaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
137 virtual void _unloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
138 virtual void _unloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
139 virtual void _reloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
140 virtual void _reloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
143 //=====================================================================
144 //= OLoadListenerAdapter
145 //=====================================================================
146 typedef ::cppu::WeakImplHelper1< ::com::sun::star::form::XLoadListener > OLoadListenerAdapter_Base;
147 class OLoadListenerAdapter
148 :public OLoadListenerAdapter_Base
149 ,public OComponentAdapterBase
151 protected:
152 OLoadListener* getLoadListener( ) { return static_cast< OLoadListener* >( getListener() ); }
154 protected:
155 virtual void disposing();
156 virtual void startComponentListening();
158 public:
159 OLoadListenerAdapter(
160 const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable,
161 sal_Bool _bAutoRelease = sal_True
165 virtual void SAL_CALL acquire( ) throw ();
166 virtual void SAL_CALL release( ) throw ();
168 protected:
169 // XEventListener
170 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException);
172 // XLoadListener
173 virtual void SAL_CALL loaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
174 virtual void SAL_CALL unloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
175 virtual void SAL_CALL unloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
176 virtual void SAL_CALL reloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
177 virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
180 //.........................................................................
181 } // namespace bib
182 //.........................................................................
184 #endif // EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX