Update ooo320-m1
[ooovba.git] / extensions / source / bibliography / loadlisteneradapter.hxx
blobf9bbb680834ad3fd208b598f3d5cd76bd58efeba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loadlisteneradapter.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX
32 #define EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX
34 #include <osl/mutex.hxx>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <cppuhelper/implbase1.hxx>
37 #include <com/sun/star/form/XLoadable.hpp>
39 //.........................................................................
40 namespace bib
42 //.........................................................................
44 class OComponentAdapterBase;
46 //=====================================================================
47 //= OComponentListener
48 //=====================================================================
49 class OComponentListener
51 friend class OComponentAdapterBase;
53 private:
54 OComponentAdapterBase* m_pAdapter;
55 ::osl::Mutex& m_rMutex;
56 protected:
57 OComponentListener( ::osl::Mutex& _rMutex )
58 :m_pAdapter( NULL )
59 ,m_rMutex( _rMutex )
63 virtual ~OComponentListener();
65 // XEventListener equivalents
66 virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException );
68 protected:
69 void setAdapter( OComponentAdapterBase* _pAdapter );
72 //=====================================================================
73 //= OComponentAdapterBase
74 //=====================================================================
75 class OComponentAdapterBase
77 friend class OComponentListener;
79 private:
80 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
81 m_xComponent;
82 OComponentListener* m_pListener;
83 sal_Int32 m_nLockCount;
84 sal_Bool m_bListening : 1;
85 sal_Bool m_bAutoRelease : 1;
87 // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster
88 virtual void disposing() = 0;
90 protected:
91 // attribute access for derivees
92 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >&
93 getComponent() const { return m_xComponent; }
94 OComponentListener* getListener() { return m_pListener; }
96 // to be called by derivees which started listening at the component
97 virtual void startComponentListening() = 0;
99 virtual ~OComponentAdapterBase();
101 public:
102 OComponentAdapterBase(
103 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp,
104 sal_Bool _bAutoRelease = sal_True
107 // late construction
108 // can be called from within you ctor, to have you're object fully initialized at the moment of
109 // the call (which would not be the case when calling this ctor)
110 void Init( OComponentListener* _pListener );
112 // base for ref-counting, implemented by OComponentAdapter
113 virtual void SAL_CALL acquire( ) throw () = 0;
114 virtual void SAL_CALL release( ) throw () = 0;
116 // helper
117 /// get the lock count
118 sal_Int32 locked() const { return m_nLockCount; }
120 /// dispose the object - stop listening and such
121 void dispose();
123 protected:
124 // XEventListener
125 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
128 //=====================================================================
129 //= OLoadListener
130 //=====================================================================
131 class OLoadListener : public OComponentListener
133 friend class OLoadListenerAdapter;
135 protected:
136 OLoadListener( ::osl::Mutex& _rMutex ) : OComponentListener( _rMutex ) { }
138 // XLoadListener equivalents
139 virtual void _loaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
140 virtual void _unloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
141 virtual void _unloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
142 virtual void _reloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
143 virtual void _reloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
146 //=====================================================================
147 //= OLoadListenerAdapter
148 //=====================================================================
149 typedef ::cppu::WeakImplHelper1< ::com::sun::star::form::XLoadListener > OLoadListenerAdapter_Base;
150 class OLoadListenerAdapter
151 :public OLoadListenerAdapter_Base
152 ,public OComponentAdapterBase
154 protected:
155 OLoadListener* getLoadListener( ) { return static_cast< OLoadListener* >( getListener() ); }
157 protected:
158 virtual void disposing();
159 virtual void startComponentListening();
161 public:
162 OLoadListenerAdapter(
163 const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable,
164 sal_Bool _bAutoRelease = sal_True
168 virtual void SAL_CALL acquire( ) throw ();
169 virtual void SAL_CALL release( ) throw ();
171 protected:
172 // XEventListener
173 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException);
175 // XLoadListener
176 virtual void SAL_CALL loaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
177 virtual void SAL_CALL unloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
178 virtual void SAL_CALL unloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
179 virtual void SAL_CALL reloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
180 virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
183 //.........................................................................
184 } // namespace bib
185 //.........................................................................
187 #endif // EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX