Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "ModifyListenerCallBack.hxx"
22 : : #include "MutexContainer.hxx"
23 : : #include <cppuhelper/compbase1.hxx>
24 : :
25 : : using namespace ::com::sun::star;
26 : : using ::com::sun::star::uno::Reference;
27 : :
28 : : namespace chart {
29 : :
30 : : typedef ::cppu::WeakComponentImplHelper1<
31 : : ::com::sun::star::util::XModifyListener >
32 : : ModifyListenerCallBack_Base;
33 : :
34 : : class ModifyListenerCallBack_impl
35 : : : public ::chart::MutexContainer
36 : : , public ModifyListenerCallBack_Base
37 : : {
38 : : public:
39 : : explicit ModifyListenerCallBack_impl( const Link& rCallBack );
40 : : virtual ~ModifyListenerCallBack_impl();
41 : :
42 : : void startListening( const Reference< util::XModifyBroadcaster >& xBroadcaster );
43 : : void stopListening();
44 : :
45 : : //XModifyListener
46 : : virtual void SAL_CALL modified( const lang::EventObject& aEvent ) throw (uno::RuntimeException);
47 : :
48 : : //XEventListener
49 : : virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException);
50 : :
51 : : using ::cppu::WeakComponentImplHelperBase::disposing;
52 : :
53 : : private:
54 : : Link m_aLink;//will be callef on modify
55 : : Reference< util::XModifyBroadcaster > m_xBroadcaster;//broadcaster to listen at
56 : : };
57 : :
58 : :
59 : 0 : ModifyListenerCallBack_impl::ModifyListenerCallBack_impl( const Link& rCallBack )
60 : : : ModifyListenerCallBack_Base( m_aMutex )
61 : : , m_aLink( rCallBack )
62 [ # # ]: 0 : , m_xBroadcaster(0)
63 : : {
64 : 0 : }
65 : :
66 [ # # ]: 0 : ModifyListenerCallBack_impl::~ModifyListenerCallBack_impl()
67 : : {
68 [ # # ]: 0 : }
69 : :
70 : : //XModifyListener
71 : 0 : void SAL_CALL ModifyListenerCallBack_impl::modified( const lang::EventObject& /*aEvent*/ ) throw (uno::RuntimeException)
72 : : {
73 : 0 : m_aLink.Call(0);
74 : 0 : }
75 : :
76 : : //XEventListener
77 : 0 : void SAL_CALL ModifyListenerCallBack_impl::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
78 : : {
79 : 0 : m_xBroadcaster.clear();
80 : 0 : }
81 : :
82 : 0 : void ModifyListenerCallBack_impl::startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >& xBroadcaster )
83 : : {
84 [ # # ]: 0 : if( m_xBroadcaster == xBroadcaster )
85 : 0 : return;
86 : :
87 : 0 : stopListening();
88 : 0 : m_xBroadcaster = xBroadcaster;
89 [ # # ]: 0 : if( m_xBroadcaster.is() )
90 [ # # ]: 0 : m_xBroadcaster->addModifyListener( this );
91 : : }
92 : 0 : void ModifyListenerCallBack_impl::stopListening()
93 : : {
94 [ # # ]: 0 : if( m_xBroadcaster.is() )
95 : : {
96 [ # # ]: 0 : m_xBroadcaster->removeModifyListener( this );
97 : 0 : m_xBroadcaster.clear();
98 : : }
99 : 0 : }
100 : :
101 : : //-------------------------------------------
102 : :
103 : 0 : ModifyListenerCallBack::ModifyListenerCallBack( const Link& rCallBack )
104 [ # # ]: 0 : : pModifyListener_impl( new ModifyListenerCallBack_impl(rCallBack) )
105 [ # # ]: 0 : , m_xModifyListener( pModifyListener_impl )
106 : : {
107 : 0 : }
108 : :
109 : 0 : ModifyListenerCallBack::~ModifyListenerCallBack()
110 : : {
111 [ # # ]: 0 : stopListening();
112 [ # # ]: 0 : }
113 : :
114 : 0 : void ModifyListenerCallBack::startListening( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >& xBroadcaster )
115 : : {
116 : 0 : pModifyListener_impl->startListening( xBroadcaster );
117 : 0 : }
118 : 0 : void ModifyListenerCallBack::stopListening()
119 : : {
120 : 0 : pModifyListener_impl->stopListening();
121 : 0 : }
122 : :
123 : : } // namespace chart
124 : :
125 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|