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 "featuredispatcher.hxx"
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::frame
;
29 using namespace ::com::sun::star::lang
;
30 using namespace ::com::sun::star::util
;
32 ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView
& _rView
, const URL
& _rURL
)
33 :m_aFeatureURL( _rURL
)
34 ,m_aStatusListeners( m_aMutex
)
35 ,m_pEditView( &_rView
)
41 ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( )
51 void ORichTextFeatureDispatcher::dispose()
53 EventObject
aEvent( *this );
54 m_aStatusListeners
.disposeAndClear( aEvent
);
56 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
62 void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard
& /*_rClearBeforeNotify*/ )
64 m_pEditView
= nullptr;
68 void SAL_CALL
ORichTextFeatureDispatcher::addStatusListener( const Reference
< XStatusListener
>& _rxControl
, const URL
& _rURL
) throw (RuntimeException
, std::exception
)
70 OSL_ENSURE( !m_bDisposed
, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" );
72 throw DisposedException();
74 OSL_ENSURE( _rURL
.Complete
== getFeatureURL().Complete
, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" );
75 if ( _rURL
.Complete
== getFeatureURL().Complete
)
76 if ( _rxControl
.is() )
78 m_aStatusListeners
.addInterface( _rxControl
);
79 newStatusListener( _rxControl
);
84 void SAL_CALL
ORichTextFeatureDispatcher::removeStatusListener( const Reference
< XStatusListener
>& _rxControl
, const URL
& /*_rURL*/ ) throw (RuntimeException
, std::exception
)
86 m_aStatusListeners
.removeInterface( _rxControl
);
90 void ORichTextFeatureDispatcher::invalidate()
92 invalidateFeatureState_Broadcast();
96 FeatureStateEvent
ORichTextFeatureDispatcher::buildStatusEvent() const
98 FeatureStateEvent aEvent
;
99 aEvent
.IsEnabled
= false;
100 aEvent
.Source
= *const_cast< ORichTextFeatureDispatcher
* >( this );
101 aEvent
.FeatureURL
= getFeatureURL();
102 aEvent
.Requery
= false;
107 void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast()
109 FeatureStateEvent
aEvent( buildStatusEvent() );
110 ::comphelper::OInterfaceIteratorHelper2
aIter( getStatusListeners() );
111 while ( aIter
.hasMoreElements() )
112 doNotify( static_cast< XStatusListener
* >( aIter
.next() ), aEvent
);
116 void ORichTextFeatureDispatcher::newStatusListener( const Reference
< XStatusListener
>& _rxListener
)
118 doNotify( _rxListener
, buildStatusEvent() );
122 void ORichTextFeatureDispatcher::doNotify( const Reference
< XStatusListener
>& _rxListener
, const FeatureStateEvent
& _rEvent
)
124 OSL_PRECOND( _rxListener
.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
125 if ( _rxListener
.is() )
129 _rxListener
->statusChanged( _rEvent
);
131 catch( const Exception
& )
133 OSL_FAIL( "ORichTextFeatureDispatcher::doNotify: caught an exception!" );
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */