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