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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_chart2.hxx" 26 27 #include "ModifyListenerCallBack.hxx" 28 #include "MutexContainer.hxx" 29 #include <cppuhelper/compbase1.hxx> 30 31 using namespace ::com::sun::star; 32 using ::com::sun::star::uno::Reference; 33 34 namespace chart { 35 36 typedef ::cppu::WeakComponentImplHelper1< 37 ::com::sun::star::util::XModifyListener > 38 ModifyListenerCallBack_Base; 39 40 class ModifyListenerCallBack_impl 41 : public ::chart::MutexContainer 42 , public ModifyListenerCallBack_Base 43 { 44 public: 45 explicit ModifyListenerCallBack_impl( const Link& rCallBack ); 46 virtual ~ModifyListenerCallBack_impl(); 47 48 void startListening( const Reference< util::XModifyBroadcaster >& xBroadcaster ); 49 void stopListening(); 50 51 //XModifyListener 52 virtual void SAL_CALL modified( const lang::EventObject& aEvent ) throw (uno::RuntimeException); 53 54 //XEventListener 55 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException); 56 57 using ::cppu::WeakComponentImplHelperBase::disposing; 58 59 private: 60 Link m_aLink;//will be callef on modify 61 Reference< util::XModifyBroadcaster > m_xBroadcaster;//broadcaster to listen at 62 }; 63 64 ModifyListenerCallBack_impl(const Link & rCallBack)65ModifyListenerCallBack_impl::ModifyListenerCallBack_impl( const Link& rCallBack ) 66 : ModifyListenerCallBack_Base( m_aMutex ) 67 , m_aLink( rCallBack ) 68 , m_xBroadcaster(0) 69 { 70 } 71 ~ModifyListenerCallBack_impl()72ModifyListenerCallBack_impl::~ModifyListenerCallBack_impl() 73 { 74 } 75 76 //XModifyListener modified(const lang::EventObject &)77void SAL_CALL ModifyListenerCallBack_impl::modified( const lang::EventObject& /*aEvent*/ ) throw (uno::RuntimeException) 78 { 79 m_aLink.Call(0); 80 } 81 82 //XEventListener disposing(const lang::EventObject &)83void SAL_CALL ModifyListenerCallBack_impl::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) 84 { 85 m_xBroadcaster.clear(); 86 } 87 startListening(const::com::sun::star::uno::Reference<::com::sun::star::util::XModifyBroadcaster> & xBroadcaster)88void ModifyListenerCallBack_impl::startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >& xBroadcaster ) 89 { 90 if( m_xBroadcaster == xBroadcaster ) 91 return; 92 93 stopListening(); 94 m_xBroadcaster = xBroadcaster; 95 if( m_xBroadcaster.is() ) 96 m_xBroadcaster->addModifyListener( this ); 97 } stopListening()98void ModifyListenerCallBack_impl::stopListening() 99 { 100 if( m_xBroadcaster.is() ) 101 { 102 m_xBroadcaster->removeModifyListener( this ); 103 m_xBroadcaster.clear(); 104 } 105 } 106 107 //------------------------------------------- 108 ModifyListenerCallBack(const Link & rCallBack)109ModifyListenerCallBack::ModifyListenerCallBack( const Link& rCallBack ) 110 : pModifyListener_impl( new ModifyListenerCallBack_impl(rCallBack) ) 111 , m_xModifyListener( pModifyListener_impl ) 112 { 113 } 114 ~ModifyListenerCallBack()115ModifyListenerCallBack::~ModifyListenerCallBack() 116 { 117 stopListening(); 118 } 119 startListening(const::com::sun::star::uno::Reference<::com::sun::star::util::XModifyBroadcaster> & xBroadcaster)120void ModifyListenerCallBack::startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >& xBroadcaster ) 121 { 122 pModifyListener_impl->startListening( xBroadcaster ); 123 } stopListening()124void ModifyListenerCallBack::stopListening() 125 { 126 pModifyListener_impl->stopListening(); 127 } 128 129 } // namespace chart 130 131