1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10*24acc546SAndrew Rist * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*24acc546SAndrew Rist * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19*24acc546SAndrew Rist * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir #include "featuredispatcher.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** === begin UNO includes === **/ 29cdf0e10cSrcweir /** === end UNO includes === **/ 30cdf0e10cSrcweir 31cdf0e10cSrcweir //........................................................................ 32cdf0e10cSrcweir namespace frm 33cdf0e10cSrcweir { 34cdf0e10cSrcweir //........................................................................ 35cdf0e10cSrcweir 36cdf0e10cSrcweir using namespace ::com::sun::star::uno; 37cdf0e10cSrcweir using namespace ::com::sun::star::frame; 38cdf0e10cSrcweir using namespace ::com::sun::star::lang; 39cdf0e10cSrcweir using namespace ::com::sun::star::util; 40cdf0e10cSrcweir 41cdf0e10cSrcweir //==================================================================== 42cdf0e10cSrcweir //= ORichTextFeatureDispatcher 43cdf0e10cSrcweir //==================================================================== 44cdf0e10cSrcweir //-------------------------------------------------------------------- ORichTextFeatureDispatcher(EditView & _rView,const URL & _rURL)45cdf0e10cSrcweir ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView& _rView, const URL& _rURL ) 46cdf0e10cSrcweir :m_aFeatureURL( _rURL ) 47cdf0e10cSrcweir ,m_aStatusListeners( m_aMutex ) 48cdf0e10cSrcweir ,m_pEditView( &_rView ) 49cdf0e10cSrcweir ,m_bDisposed( false ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir //-------------------------------------------------------------------- ~ORichTextFeatureDispatcher()54cdf0e10cSrcweir ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir if ( !m_bDisposed ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir acquire(); 59cdf0e10cSrcweir dispose(); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir //-------------------------------------------------------------------- dispose()64cdf0e10cSrcweir void ORichTextFeatureDispatcher::dispose() 65cdf0e10cSrcweir { 66cdf0e10cSrcweir EventObject aEvent( *this ); 67cdf0e10cSrcweir m_aStatusListeners.disposeAndClear( aEvent ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex ); 70cdf0e10cSrcweir m_bDisposed = true; 71cdf0e10cSrcweir disposing( aGuard ); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir //-------------------------------------------------------------------- disposing(::osl::ClearableMutexGuard &)75cdf0e10cSrcweir void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard& /*_rClearBeforeNotify*/ ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir m_pEditView = NULL; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir //-------------------------------------------------------------------- addStatusListener(const Reference<XStatusListener> & _rxControl,const URL & _rURL)81cdf0e10cSrcweir void SAL_CALL ORichTextFeatureDispatcher::addStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL ) throw (RuntimeException) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir OSL_ENSURE( !m_bDisposed, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" ); 84cdf0e10cSrcweir if ( m_bDisposed ) 85cdf0e10cSrcweir throw DisposedException(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" ); 88cdf0e10cSrcweir if ( _rURL.Complete == getFeatureURL().Complete ) 89cdf0e10cSrcweir if ( _rxControl.is() ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir m_aStatusListeners.addInterface( _rxControl ); 92cdf0e10cSrcweir newStatusListener( _rxControl ); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir //-------------------------------------------------------------------- removeStatusListener(const Reference<XStatusListener> & _rxControl,const URL &)97cdf0e10cSrcweir void SAL_CALL ORichTextFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& /*_rURL*/ ) throw (RuntimeException) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir m_aStatusListeners.removeInterface( _rxControl ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir //-------------------------------------------------------------------- invalidate()103cdf0e10cSrcweir void ORichTextFeatureDispatcher::invalidate() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir invalidateFeatureState_Broadcast(); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir //-------------------------------------------------------------------- buildStatusEvent() const109cdf0e10cSrcweir FeatureStateEvent ORichTextFeatureDispatcher::buildStatusEvent() const 110cdf0e10cSrcweir { 111cdf0e10cSrcweir FeatureStateEvent aEvent; 112cdf0e10cSrcweir aEvent.IsEnabled = sal_False; 113cdf0e10cSrcweir aEvent.Source = *const_cast< ORichTextFeatureDispatcher* >( this ); 114cdf0e10cSrcweir aEvent.FeatureURL = getFeatureURL(); 115cdf0e10cSrcweir aEvent.Requery = sal_False; 116cdf0e10cSrcweir return aEvent; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir //-------------------------------------------------------------------- invalidateFeatureState_Broadcast()120cdf0e10cSrcweir void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir FeatureStateEvent aEvent( buildStatusEvent() ); 123cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() ); 124cdf0e10cSrcweir while ( aIter.hasMoreElements() ) 125cdf0e10cSrcweir doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir //-------------------------------------------------------------------- newStatusListener(const Reference<XStatusListener> & _rxListener)129cdf0e10cSrcweir void ORichTextFeatureDispatcher::newStatusListener( const Reference< XStatusListener >& _rxListener ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir doNotify( _rxListener, buildStatusEvent() ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir //-------------------------------------------------------------------- doNotify(const Reference<XStatusListener> & _rxListener,const FeatureStateEvent & _rEvent) const135cdf0e10cSrcweir void ORichTextFeatureDispatcher::doNotify( const Reference< XStatusListener >& _rxListener, const FeatureStateEvent& _rEvent ) const SAL_THROW(()) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir OSL_PRECOND( _rxListener.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" ); 138cdf0e10cSrcweir if ( _rxListener.is() ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir try 141cdf0e10cSrcweir { 142cdf0e10cSrcweir _rxListener->statusChanged( _rEvent ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir catch( const Exception& ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir OSL_ENSURE( sal_False, "ORichTextFeatureDispatcher::doNotify: caught an exception!" ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir //........................................................................ 152cdf0e10cSrcweir } // namespace frm 153cdf0e10cSrcweir //........................................................................ 154