update dev300-m58
[ooovba.git] / chart2 / source / tools / ModifyListenerCallBack.cxx
blobe2a238dd781a930b07ee33f69fa2d1b9a47ccabf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ModifyListenerCallBack.cxx,v $
10 * $Revision: 1.5 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "ModifyListenerCallBack.hxx"
35 #include "MutexContainer.hxx"
36 #include <cppuhelper/compbase1.hxx>
38 using namespace ::com::sun::star;
39 using ::com::sun::star::uno::Reference;
41 namespace chart {
43 typedef ::cppu::WeakComponentImplHelper1<
44 ::com::sun::star::util::XModifyListener >
45 ModifyListenerCallBack_Base;
47 class ModifyListenerCallBack_impl
48 : public ::chart::MutexContainer
49 , public ModifyListenerCallBack_Base
51 public:
52 explicit ModifyListenerCallBack_impl( const Link& rCallBack );
53 virtual ~ModifyListenerCallBack_impl();
55 void startListening( const Reference< util::XModifyBroadcaster >& xBroadcaster );
56 void stopListening();
58 //XModifyListener
59 virtual void SAL_CALL modified( const lang::EventObject& aEvent ) throw (uno::RuntimeException);
61 //XEventListener
62 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException);
64 using ::cppu::WeakComponentImplHelperBase::disposing;
66 private:
67 Link m_aLink;//will be callef on modify
68 Reference< util::XModifyBroadcaster > m_xBroadcaster;//broadcaster to listen at
72 ModifyListenerCallBack_impl::ModifyListenerCallBack_impl( const Link& rCallBack )
73 : ModifyListenerCallBack_Base( m_aMutex )
74 , m_aLink( rCallBack )
75 , m_xBroadcaster(0)
79 ModifyListenerCallBack_impl::~ModifyListenerCallBack_impl()
83 //XModifyListener
84 void SAL_CALL ModifyListenerCallBack_impl::modified( const lang::EventObject& /*aEvent*/ ) throw (uno::RuntimeException)
86 m_aLink.Call(0);
89 //XEventListener
90 void SAL_CALL ModifyListenerCallBack_impl::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
92 m_xBroadcaster.clear();
95 void ModifyListenerCallBack_impl::startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >& xBroadcaster )
97 if( m_xBroadcaster == xBroadcaster )
98 return;
100 stopListening();
101 m_xBroadcaster = xBroadcaster;
102 if( m_xBroadcaster.is() )
103 m_xBroadcaster->addModifyListener( this );
105 void ModifyListenerCallBack_impl::stopListening()
107 if( m_xBroadcaster.is() )
109 m_xBroadcaster->removeModifyListener( this );
110 m_xBroadcaster.clear();
114 //-------------------------------------------
116 ModifyListenerCallBack::ModifyListenerCallBack( const Link& rCallBack )
117 : pModifyListener_impl( new ModifyListenerCallBack_impl(rCallBack) )
118 , m_xModifyListener( pModifyListener_impl )
122 ModifyListenerCallBack::~ModifyListenerCallBack()
124 stopListening();
127 void ModifyListenerCallBack::startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >& xBroadcaster )
129 pModifyListener_impl->startListening( xBroadcaster );
131 void ModifyListenerCallBack::stopListening()
133 pModifyListener_impl->stopListening();
136 } // namespace chart