Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / extensions / source / bibliography / loadlisteneradapter.hxx
blobc9811be69e477656a415053e0b0b19520e5540fe
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 EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX
21 #define EXTENSIONS_BIB_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>
28 //.........................................................................
29 namespace bib
31 //.........................................................................
33 class OComponentAdapterBase;
35 //=====================================================================
36 //= OComponentListener
37 //=====================================================================
38 class OComponentListener
40 friend class OComponentAdapterBase;
42 private:
43 OComponentAdapterBase* m_pAdapter;
44 ::osl::Mutex& m_rMutex;
45 protected:
46 OComponentListener( ::osl::Mutex& _rMutex )
47 :m_pAdapter( NULL )
48 ,m_rMutex( _rMutex )
52 virtual ~OComponentListener();
54 // XEventListener equivalents
55 virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException );
57 protected:
58 void setAdapter( OComponentAdapterBase* _pAdapter );
61 //=====================================================================
62 //= OComponentAdapterBase
63 //=====================================================================
64 class OComponentAdapterBase
66 friend class OComponentListener;
68 private:
69 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
70 m_xComponent;
71 OComponentListener* m_pListener;
72 sal_Int32 m_nLockCount;
73 sal_Bool m_bListening : 1;
74 sal_Bool m_bAutoRelease : 1;
76 // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster
77 virtual void disposing() = 0;
79 protected:
80 // attribute access for derivees
81 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >&
82 getComponent() const { return m_xComponent; }
83 OComponentListener* getListener() { return m_pListener; }
85 // to be called by derivees which started listening at the component
86 virtual void startComponentListening() = 0;
88 virtual ~OComponentAdapterBase();
90 public:
91 OComponentAdapterBase(
92 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp,
93 sal_Bool _bAutoRelease = sal_True
96 // late construction
97 // can be called from within you ctor, to have you're object fully initialized at the moment of
98 // the call (which would not be the case when calling this ctor)
99 void Init( OComponentListener* _pListener );
101 // base for ref-counting, implemented by OComponentAdapter
102 virtual void SAL_CALL acquire( ) throw () = 0;
103 virtual void SAL_CALL release( ) throw () = 0;
105 // helper
106 /// get the lock count
107 sal_Int32 locked() const { return m_nLockCount; }
109 /// dispose the object - stop listening and such
110 void dispose();
112 protected:
113 // XEventListener
114 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
117 //=====================================================================
118 //= OLoadListener
119 //=====================================================================
120 class OLoadListener : public OComponentListener
122 friend class OLoadListenerAdapter;
124 protected:
125 OLoadListener( ::osl::Mutex& _rMutex ) : OComponentListener( _rMutex ) { }
127 // XLoadListener equivalents
128 virtual void _loaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
129 virtual void _unloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
130 virtual void _unloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
131 virtual void _reloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
132 virtual void _reloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
135 //=====================================================================
136 //= OLoadListenerAdapter
137 //=====================================================================
138 typedef ::cppu::WeakImplHelper1< ::com::sun::star::form::XLoadListener > OLoadListenerAdapter_Base;
139 class OLoadListenerAdapter
140 :public OLoadListenerAdapter_Base
141 ,public OComponentAdapterBase
143 protected:
144 OLoadListener* getLoadListener( ) { return static_cast< OLoadListener* >( getListener() ); }
146 protected:
147 virtual void disposing();
148 virtual void startComponentListening();
150 public:
151 OLoadListenerAdapter(
152 const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable,
153 sal_Bool _bAutoRelease = sal_True
157 virtual void SAL_CALL acquire( ) throw ();
158 virtual void SAL_CALL release( ) throw ();
160 protected:
161 // XEventListener
162 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException);
164 // XLoadListener
165 virtual void SAL_CALL loaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
166 virtual void SAL_CALL unloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
167 virtual void SAL_CALL unloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
168 virtual void SAL_CALL reloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
169 virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
172 //.........................................................................
173 } // namespace bib
174 //.........................................................................
176 #endif // EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */