1*46dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*46dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*46dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*46dbaceeSAndrew Rist * distributed with this work for additional information 6*46dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*46dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*46dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 9*46dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 10*46dbaceeSAndrew Rist * 11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*46dbaceeSAndrew Rist * 13*46dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*46dbaceeSAndrew Rist * software distributed under the License is distributed on an 15*46dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*46dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 17*46dbaceeSAndrew Rist * specific language governing permissions and limitations 18*46dbaceeSAndrew Rist * under the License. 19*46dbaceeSAndrew Rist * 20*46dbaceeSAndrew Rist *************************************************************/ 21*46dbaceeSAndrew Rist 22*46dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX 25cdf0e10cSrcweir #define EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <osl/mutex.hxx> 28cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 29cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 30cdf0e10cSrcweir #include <com/sun/star/form/XLoadable.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir //......................................................................... 33cdf0e10cSrcweir namespace bib 34cdf0e10cSrcweir { 35cdf0e10cSrcweir //......................................................................... 36cdf0e10cSrcweir 37cdf0e10cSrcweir class OComponentAdapterBase; 38cdf0e10cSrcweir 39cdf0e10cSrcweir //===================================================================== 40cdf0e10cSrcweir //= OComponentListener 41cdf0e10cSrcweir //===================================================================== 42cdf0e10cSrcweir class OComponentListener 43cdf0e10cSrcweir { 44cdf0e10cSrcweir friend class OComponentAdapterBase; 45cdf0e10cSrcweir 46cdf0e10cSrcweir private: 47cdf0e10cSrcweir OComponentAdapterBase* m_pAdapter; 48cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 49cdf0e10cSrcweir protected: OComponentListener(::osl::Mutex & _rMutex)50cdf0e10cSrcweir OComponentListener( ::osl::Mutex& _rMutex ) 51cdf0e10cSrcweir :m_pAdapter( NULL ) 52cdf0e10cSrcweir ,m_rMutex( _rMutex ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir virtual ~OComponentListener(); 57cdf0e10cSrcweir 58cdf0e10cSrcweir // XEventListener equivalents 59cdf0e10cSrcweir virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir protected: 62cdf0e10cSrcweir void setAdapter( OComponentAdapterBase* _pAdapter ); 63cdf0e10cSrcweir }; 64cdf0e10cSrcweir 65cdf0e10cSrcweir //===================================================================== 66cdf0e10cSrcweir //= OComponentAdapterBase 67cdf0e10cSrcweir //===================================================================== 68cdf0e10cSrcweir class OComponentAdapterBase 69cdf0e10cSrcweir { 70cdf0e10cSrcweir friend class OComponentListener; 71cdf0e10cSrcweir 72cdf0e10cSrcweir private: 73cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > 74cdf0e10cSrcweir m_xComponent; 75cdf0e10cSrcweir OComponentListener* m_pListener; 76cdf0e10cSrcweir sal_Int32 m_nLockCount; 77cdf0e10cSrcweir sal_Bool m_bListening : 1; 78cdf0e10cSrcweir sal_Bool m_bAutoRelease : 1; 79cdf0e10cSrcweir 80cdf0e10cSrcweir // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster 81cdf0e10cSrcweir virtual void disposing() = 0; 82cdf0e10cSrcweir 83cdf0e10cSrcweir protected: 84cdf0e10cSrcweir // attribute access for derivees 85cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& getComponent() const86cdf0e10cSrcweir getComponent() const { return m_xComponent; } getListener()87cdf0e10cSrcweir OComponentListener* getListener() { return m_pListener; } 88cdf0e10cSrcweir 89cdf0e10cSrcweir // to be called by derivees which started listening at the component 90cdf0e10cSrcweir virtual void startComponentListening() = 0; 91cdf0e10cSrcweir 92cdf0e10cSrcweir virtual ~OComponentAdapterBase(); 93cdf0e10cSrcweir 94cdf0e10cSrcweir public: 95cdf0e10cSrcweir OComponentAdapterBase( 96cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp, 97cdf0e10cSrcweir sal_Bool _bAutoRelease = sal_True 98cdf0e10cSrcweir ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // late construction 101cdf0e10cSrcweir // can be called from within you ctor, to have you're object fully initialized at the moment of 102cdf0e10cSrcweir // the call (which would not be the case when calling this ctor) 103cdf0e10cSrcweir void Init( OComponentListener* _pListener ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir // base for ref-counting, implemented by OComponentAdapter 106cdf0e10cSrcweir virtual void SAL_CALL acquire( ) throw () = 0; 107cdf0e10cSrcweir virtual void SAL_CALL release( ) throw () = 0; 108cdf0e10cSrcweir 109cdf0e10cSrcweir // helper 110cdf0e10cSrcweir /// get the lock count locked() const111cdf0e10cSrcweir sal_Int32 locked() const { return m_nLockCount; } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /// dispose the object - stop listening and such 114cdf0e10cSrcweir void dispose(); 115cdf0e10cSrcweir 116cdf0e10cSrcweir protected: 117cdf0e10cSrcweir // XEventListener 118cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException); 119cdf0e10cSrcweir }; 120cdf0e10cSrcweir 121cdf0e10cSrcweir //===================================================================== 122cdf0e10cSrcweir //= OLoadListener 123cdf0e10cSrcweir //===================================================================== 124cdf0e10cSrcweir class OLoadListener : public OComponentListener 125cdf0e10cSrcweir { 126cdf0e10cSrcweir friend class OLoadListenerAdapter; 127cdf0e10cSrcweir 128cdf0e10cSrcweir protected: OLoadListener(::osl::Mutex & _rMutex)129cdf0e10cSrcweir OLoadListener( ::osl::Mutex& _rMutex ) : OComponentListener( _rMutex ) { } 130cdf0e10cSrcweir 131cdf0e10cSrcweir // XLoadListener equivalents 132cdf0e10cSrcweir virtual void _loaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0; 133cdf0e10cSrcweir virtual void _unloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0; 134cdf0e10cSrcweir virtual void _unloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0; 135cdf0e10cSrcweir virtual void _reloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0; 136cdf0e10cSrcweir virtual void _reloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0; 137cdf0e10cSrcweir }; 138cdf0e10cSrcweir 139cdf0e10cSrcweir //===================================================================== 140cdf0e10cSrcweir //= OLoadListenerAdapter 141cdf0e10cSrcweir //===================================================================== 142cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< ::com::sun::star::form::XLoadListener > OLoadListenerAdapter_Base; 143cdf0e10cSrcweir class OLoadListenerAdapter 144cdf0e10cSrcweir :public OLoadListenerAdapter_Base 145cdf0e10cSrcweir ,public OComponentAdapterBase 146cdf0e10cSrcweir { 147cdf0e10cSrcweir protected: getLoadListener()148cdf0e10cSrcweir OLoadListener* getLoadListener( ) { return static_cast< OLoadListener* >( getListener() ); } 149cdf0e10cSrcweir 150cdf0e10cSrcweir protected: 151cdf0e10cSrcweir virtual void disposing(); 152cdf0e10cSrcweir virtual void startComponentListening(); 153cdf0e10cSrcweir 154cdf0e10cSrcweir public: 155cdf0e10cSrcweir OLoadListenerAdapter( 156cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable, 157cdf0e10cSrcweir sal_Bool _bAutoRelease = sal_True 158cdf0e10cSrcweir ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir 161cdf0e10cSrcweir virtual void SAL_CALL acquire( ) throw (); 162cdf0e10cSrcweir virtual void SAL_CALL release( ) throw (); 163cdf0e10cSrcweir 164cdf0e10cSrcweir protected: 165cdf0e10cSrcweir // XEventListener 166cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException); 167cdf0e10cSrcweir 168cdf0e10cSrcweir // XLoadListener 169cdf0e10cSrcweir virtual void SAL_CALL loaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 170cdf0e10cSrcweir virtual void SAL_CALL unloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 171cdf0e10cSrcweir virtual void SAL_CALL unloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 172cdf0e10cSrcweir virtual void SAL_CALL reloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 173cdf0e10cSrcweir virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 174cdf0e10cSrcweir }; 175cdf0e10cSrcweir 176cdf0e10cSrcweir //......................................................................... 177cdf0e10cSrcweir } // namespace bib 178cdf0e10cSrcweir //......................................................................... 179cdf0e10cSrcweir 180cdf0e10cSrcweir #endif // EXTENSIONS_BIB_LOADLISTENERADAPTER_HXX 181cdf0e10cSrcweir 182