LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / richtext / featuredispatcher.cxx
blobd667790c97563fdf851c84e665a71db3f01ccade
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"
21 #include <osl/diagnose.h>
22 #include <tools/diagnose_ex.h>
25 namespace frm
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::frame;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::util;
34 ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView& _rView, const URL& _rURL )
35 :m_aFeatureURL( _rURL )
36 ,m_aStatusListeners( m_aMutex )
37 ,m_pEditView( &_rView )
38 ,m_bDisposed( false )
43 ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( )
45 if ( !m_bDisposed )
47 acquire();
48 dispose();
53 void ORichTextFeatureDispatcher::dispose()
55 EventObject aEvent( *this );
56 m_aStatusListeners.disposeAndClear( aEvent );
58 ::osl::ClearableMutexGuard aGuard( m_aMutex );
59 m_bDisposed = true;
60 disposing( aGuard );
64 void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard& /*_rClearBeforeNotify*/ )
66 m_pEditView = nullptr;
70 void SAL_CALL ORichTextFeatureDispatcher::addStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL )
72 OSL_ENSURE( !m_bDisposed, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" );
73 if ( m_bDisposed )
74 throw DisposedException();
76 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" );
77 if ( _rURL.Complete == getFeatureURL().Complete )
78 if ( _rxControl.is() )
80 m_aStatusListeners.addInterface( _rxControl );
81 doNotify( _rxControl, buildStatusEvent() );
86 void SAL_CALL ORichTextFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& /*_rURL*/ )
88 m_aStatusListeners.removeInterface( _rxControl );
92 void ORichTextFeatureDispatcher::invalidate()
94 invalidateFeatureState_Broadcast();
98 FeatureStateEvent ORichTextFeatureDispatcher::buildStatusEvent() const
100 FeatureStateEvent aEvent;
101 aEvent.IsEnabled = false;
102 aEvent.Source = *const_cast< ORichTextFeatureDispatcher* >( this );
103 aEvent.FeatureURL = getFeatureURL();
104 aEvent.Requery = false;
105 return aEvent;
109 void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast()
111 FeatureStateEvent aEvent( buildStatusEvent() );
112 ::comphelper::OInterfaceIteratorHelper2 aIter( getStatusListeners() );
113 while ( aIter.hasMoreElements() )
114 doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
118 void ORichTextFeatureDispatcher::doNotify( const Reference< XStatusListener >& _rxListener, const FeatureStateEvent& _rEvent )
120 OSL_PRECOND( _rxListener.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
121 if ( _rxListener.is() )
125 _rxListener->statusChanged( _rEvent );
127 catch( const Exception& )
129 TOOLS_WARN_EXCEPTION( "forms.richtext", "ORichTextFeatureDispatcher::doNotify" );
135 } // namespace frm
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */