1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <ModifyListenerCallBack.hxx>
21 #include <comphelper/compbase.hxx>
23 using namespace ::com::sun::star
;
24 using ::com::sun::star::uno::Reference
;
28 typedef comphelper::WeakComponentImplHelper
< css::util::XModifyListener
>
29 ModifyListenerCallBack_Base
;
31 class ModifyListenerCallBack_impl
32 : public ModifyListenerCallBack_Base
35 explicit ModifyListenerCallBack_impl( const Link
<void*,void>& rCallBack
);
37 void startListening( const Reference
< util::XModifyBroadcaster
>& xBroadcaster
);
41 virtual void SAL_CALL
modified( const lang::EventObject
& aEvent
) override
;
44 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) override
;
46 using ::comphelper::WeakComponentImplHelperBase::disposing
;
49 Link
<void*,void> m_aLink
;//will be called on modify
50 Reference
< util::XModifyBroadcaster
> m_xBroadcaster
;//broadcaster to listen at
53 ModifyListenerCallBack_impl::ModifyListenerCallBack_impl( const Link
<void*,void>& rCallBack
)
54 : m_aLink( rCallBack
)
59 void SAL_CALL
ModifyListenerCallBack_impl::modified( const lang::EventObject
& /*aEvent*/ )
61 m_aLink
.Call(nullptr);
65 void SAL_CALL
ModifyListenerCallBack_impl::disposing( const lang::EventObject
& /*Source*/ )
67 m_xBroadcaster
.clear();
70 void ModifyListenerCallBack_impl::startListening( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyBroadcaster
>& xBroadcaster
)
72 if( m_xBroadcaster
== xBroadcaster
)
76 m_xBroadcaster
= xBroadcaster
;
77 if( m_xBroadcaster
.is() )
78 m_xBroadcaster
->addModifyListener( this );
80 void ModifyListenerCallBack_impl::stopListening()
82 if( m_xBroadcaster
.is() )
84 m_xBroadcaster
->removeModifyListener( this );
85 m_xBroadcaster
.clear();
89 ModifyListenerCallBack::ModifyListenerCallBack( const Link
<void*,void>& rCallBack
)
90 : pModifyListener_impl( new ModifyListenerCallBack_impl(rCallBack
) )
91 , m_xModifyListener( pModifyListener_impl
)
95 ModifyListenerCallBack::~ModifyListenerCallBack()
100 void ModifyListenerCallBack::startListening( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyBroadcaster
>& xBroadcaster
)
102 pModifyListener_impl
->startListening( xBroadcaster
);
104 void ModifyListenerCallBack::stopListening()
106 pModifyListener_impl
->stopListening();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */