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