1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loadlisteneradapter.hxx,v $
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 //.........................................................................
42 //.........................................................................
44 class OComponentAdapterBase
;
46 //=====================================================================
47 //= OComponentListener
48 //=====================================================================
49 class OComponentListener
51 friend class OComponentAdapterBase
;
54 OComponentAdapterBase
* m_pAdapter
;
55 ::osl::Mutex
& m_rMutex
;
57 OComponentListener( ::osl::Mutex
& _rMutex
)
63 virtual ~OComponentListener();
65 // XEventListener equivalents
66 virtual void _disposing( const ::com::sun::star::lang::EventObject
& _rSource
) throw( ::com::sun::star::uno::RuntimeException
);
69 void setAdapter( OComponentAdapterBase
* _pAdapter
);
72 //=====================================================================
73 //= OComponentAdapterBase
74 //=====================================================================
75 class OComponentAdapterBase
77 friend class OComponentListener
;
80 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::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;
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();
102 OComponentAdapterBase(
103 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& _rxComp
,
104 sal_Bool _bAutoRelease
= sal_True
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;
117 /// get the lock count
118 sal_Int32
locked() const { return m_nLockCount
; }
120 /// dispose the object - stop listening and such
125 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
);
128 //=====================================================================
130 //=====================================================================
131 class OLoadListener
: public OComponentListener
133 friend class OLoadListenerAdapter
;
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
155 OLoadListener
* getLoadListener( ) { return static_cast< OLoadListener
* >( getListener() ); }
158 virtual void disposing();
159 virtual void startComponentListening();
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 ();
173 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& _rSource
) throw( ::com::sun::star::uno::RuntimeException
);
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 //.........................................................................
185 //.........................................................................
187 #endif // EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX