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"
21 #include <osl/diagnose.h>
22 #include <comphelper/diagnose_ex.hxx>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::frame
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star::util
;
36 ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView
& _rView
, URL _aURL
)
37 :m_aFeatureURL(std::move( _aURL
))
38 ,m_aStatusListeners( m_aMutex
)
39 ,m_pEditView( &_rView
)
45 ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( )
55 void ORichTextFeatureDispatcher::dispose()
57 EventObject
aEvent( *this );
58 m_aStatusListeners
.disposeAndClear( aEvent
);
60 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
66 void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard
& /*_rClearBeforeNotify*/ )
68 m_pEditView
= nullptr;
72 void SAL_CALL
ORichTextFeatureDispatcher::addStatusListener( const Reference
< XStatusListener
>& _rxControl
, const URL
& _rURL
)
74 OSL_ENSURE( !m_bDisposed
, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" );
76 throw DisposedException();
78 OSL_ENSURE( _rURL
.Complete
== getFeatureURL().Complete
, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" );
79 if ( _rURL
.Complete
== getFeatureURL().Complete
)
80 if ( _rxControl
.is() )
82 m_aStatusListeners
.addInterface( _rxControl
);
83 doNotify( _rxControl
, buildStatusEvent() );
88 void SAL_CALL
ORichTextFeatureDispatcher::removeStatusListener( const Reference
< XStatusListener
>& _rxControl
, const URL
& /*_rURL*/ )
90 m_aStatusListeners
.removeInterface( _rxControl
);
94 void ORichTextFeatureDispatcher::invalidate()
96 invalidateFeatureState_Broadcast();
100 FeatureStateEvent
ORichTextFeatureDispatcher::buildStatusEvent() const
102 FeatureStateEvent aEvent
;
103 aEvent
.IsEnabled
= false;
104 aEvent
.Source
= *const_cast< ORichTextFeatureDispatcher
* >( this );
105 aEvent
.FeatureURL
= getFeatureURL();
106 aEvent
.Requery
= false;
111 void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast()
113 FeatureStateEvent
aEvent( buildStatusEvent() );
114 ::comphelper::OInterfaceIteratorHelper3
aIter( getStatusListeners() );
115 while ( aIter
.hasMoreElements() )
116 doNotify( aIter
.next(), aEvent
);
120 void ORichTextFeatureDispatcher::doNotify( const Reference
< XStatusListener
>& _rxListener
, const FeatureStateEvent
& _rEvent
)
122 OSL_PRECOND( _rxListener
.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
123 if ( _rxListener
.is() )
127 _rxListener
->statusChanged( _rEvent
);
129 catch( const Exception
& )
131 TOOLS_WARN_EXCEPTION( "forms.richtext", "ORichTextFeatureDispatcher::doNotify" );
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */