update dev300-m58
[ooovba.git] / forms / source / richtext / featuredispatcher.cxx
blob752268e7a4d54efe11c1170e70de527a5d15fbe6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: featuredispatcher.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "featuredispatcher.hxx"
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
38 //........................................................................
39 namespace frm
41 //........................................................................
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::frame;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::util;
48 //====================================================================
49 //= ORichTextFeatureDispatcher
50 //====================================================================
51 //--------------------------------------------------------------------
52 ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView& _rView, const URL& _rURL )
53 :m_aFeatureURL( _rURL )
54 ,m_aStatusListeners( m_aMutex )
55 ,m_pEditView( &_rView )
56 ,m_bDisposed( false )
60 //--------------------------------------------------------------------
61 ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( )
63 if ( !m_bDisposed )
65 acquire();
66 dispose();
70 //--------------------------------------------------------------------
71 void ORichTextFeatureDispatcher::dispose()
73 EventObject aEvent( *this );
74 m_aStatusListeners.disposeAndClear( aEvent );
76 ::osl::ClearableMutexGuard aGuard( m_aMutex );
77 m_bDisposed = true;
78 disposing( aGuard );
81 //--------------------------------------------------------------------
82 void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard& /*_rClearBeforeNotify*/ )
84 m_pEditView = NULL;
87 //--------------------------------------------------------------------
88 void SAL_CALL ORichTextFeatureDispatcher::addStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL ) throw (RuntimeException)
90 OSL_ENSURE( !m_bDisposed, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" );
91 if ( m_bDisposed )
92 throw DisposedException();
94 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" );
95 if ( _rURL.Complete == getFeatureURL().Complete )
96 if ( _rxControl.is() )
98 m_aStatusListeners.addInterface( _rxControl );
99 newStatusListener( _rxControl );
103 //--------------------------------------------------------------------
104 void SAL_CALL ORichTextFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& /*_rURL*/ ) throw (RuntimeException)
106 m_aStatusListeners.removeInterface( _rxControl );
109 //--------------------------------------------------------------------
110 void ORichTextFeatureDispatcher::invalidate()
112 invalidateFeatureState_Broadcast();
115 //--------------------------------------------------------------------
116 FeatureStateEvent ORichTextFeatureDispatcher::buildStatusEvent() const
118 FeatureStateEvent aEvent;
119 aEvent.IsEnabled = sal_False;
120 aEvent.Source = *const_cast< ORichTextFeatureDispatcher* >( this );
121 aEvent.FeatureURL = getFeatureURL();
122 aEvent.Requery = sal_False;
123 return aEvent;
126 //--------------------------------------------------------------------
127 void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast()
129 FeatureStateEvent aEvent( buildStatusEvent() );
130 ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() );
131 while ( aIter.hasMoreElements() )
132 doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
135 //--------------------------------------------------------------------
136 void ORichTextFeatureDispatcher::newStatusListener( const Reference< XStatusListener >& _rxListener )
138 doNotify( _rxListener, buildStatusEvent() );
141 //--------------------------------------------------------------------
142 void ORichTextFeatureDispatcher::doNotify( const Reference< XStatusListener >& _rxListener, const FeatureStateEvent& _rEvent ) const SAL_THROW(())
144 OSL_PRECOND( _rxListener.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
145 if ( _rxListener.is() )
149 _rxListener->statusChanged( _rEvent );
151 catch( const Exception& )
153 OSL_ENSURE( sal_False, "ORichTextFeatureDispatcher::doNotify: caught an exception!" );
158 //........................................................................
159 } // namespace frm
160 //........................................................................