update credits
[LibreOffice.git] / forms / source / richtext / featuredispatcher.cxx
blobbc7d66af02a8f1500384c4cd0e15b27eb700a949
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 //........................................................................
23 namespace frm
25 //........................................................................
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 //====================================================================
33 //= ORichTextFeatureDispatcher
34 //====================================================================
35 //--------------------------------------------------------------------
36 ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView& _rView, const URL& _rURL )
37 :m_aFeatureURL( _rURL )
38 ,m_aStatusListeners( m_aMutex )
39 ,m_pEditView( &_rView )
40 ,m_bDisposed( false )
44 //--------------------------------------------------------------------
45 ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( )
47 if ( !m_bDisposed )
49 acquire();
50 dispose();
54 //--------------------------------------------------------------------
55 void ORichTextFeatureDispatcher::dispose()
57 EventObject aEvent( *this );
58 m_aStatusListeners.disposeAndClear( aEvent );
60 ::osl::ClearableMutexGuard aGuard( m_aMutex );
61 m_bDisposed = true;
62 disposing( aGuard );
65 //--------------------------------------------------------------------
66 void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard& /*_rClearBeforeNotify*/ )
68 m_pEditView = NULL;
71 //--------------------------------------------------------------------
72 void SAL_CALL ORichTextFeatureDispatcher::addStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL ) throw (RuntimeException)
74 OSL_ENSURE( !m_bDisposed, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" );
75 if ( m_bDisposed )
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 newStatusListener( _rxControl );
87 //--------------------------------------------------------------------
88 void SAL_CALL ORichTextFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& /*_rURL*/ ) throw (RuntimeException)
90 m_aStatusListeners.removeInterface( _rxControl );
93 //--------------------------------------------------------------------
94 void ORichTextFeatureDispatcher::invalidate()
96 invalidateFeatureState_Broadcast();
99 //--------------------------------------------------------------------
100 FeatureStateEvent ORichTextFeatureDispatcher::buildStatusEvent() const
102 FeatureStateEvent aEvent;
103 aEvent.IsEnabled = sal_False;
104 aEvent.Source = *const_cast< ORichTextFeatureDispatcher* >( this );
105 aEvent.FeatureURL = getFeatureURL();
106 aEvent.Requery = sal_False;
107 return aEvent;
110 //--------------------------------------------------------------------
111 void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast()
113 FeatureStateEvent aEvent( buildStatusEvent() );
114 ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() );
115 while ( aIter.hasMoreElements() )
116 doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
119 //--------------------------------------------------------------------
120 void ORichTextFeatureDispatcher::newStatusListener( const Reference< XStatusListener >& _rxListener )
122 doNotify( _rxListener, buildStatusEvent() );
125 //--------------------------------------------------------------------
126 void ORichTextFeatureDispatcher::doNotify( const Reference< XStatusListener >& _rxListener, const FeatureStateEvent& _rEvent ) const SAL_THROW(())
128 OSL_PRECOND( _rxListener.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
129 if ( _rxListener.is() )
133 _rxListener->statusChanged( _rEvent );
135 catch( const Exception& )
137 OSL_FAIL( "ORichTextFeatureDispatcher::doNotify: caught an exception!" );
142 //........................................................................
143 } // namespace frm
144 //........................................................................
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */