Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "featuredispatcher.hxx"
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 : : //--------------------------------------------------------------------
45 : 0 : ORichTextFeatureDispatcher::ORichTextFeatureDispatcher( EditView& _rView, const URL& _rURL )
46 : : :m_aFeatureURL( _rURL )
47 : : ,m_aStatusListeners( m_aMutex )
48 : : ,m_pEditView( &_rView )
49 [ # # ][ # # ]: 0 : ,m_bDisposed( false )
50 : : {
51 : 0 : }
52 : :
53 : : //--------------------------------------------------------------------
54 [ # # ][ # # ]: 0 : ORichTextFeatureDispatcher::~ORichTextFeatureDispatcher( )
55 : : {
56 [ # # ]: 0 : if ( !m_bDisposed )
57 : : {
58 : 0 : acquire();
59 [ # # ]: 0 : dispose();
60 : : }
61 [ # # ]: 0 : }
62 : :
63 : : //--------------------------------------------------------------------
64 : 0 : void ORichTextFeatureDispatcher::dispose()
65 : : {
66 [ # # ][ # # ]: 0 : EventObject aEvent( *this );
67 [ # # ]: 0 : m_aStatusListeners.disposeAndClear( aEvent );
68 : :
69 [ # # ]: 0 : ::osl::ClearableMutexGuard aGuard( m_aMutex );
70 : 0 : m_bDisposed = true;
71 [ # # ][ # # ]: 0 : disposing( aGuard );
[ # # ]
72 : 0 : }
73 : :
74 : : //--------------------------------------------------------------------
75 : 0 : void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard& /*_rClearBeforeNotify*/ )
76 : : {
77 : 0 : m_pEditView = NULL;
78 : 0 : }
79 : :
80 : : //--------------------------------------------------------------------
81 : 0 : 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 [ # # ]: 0 : if ( m_bDisposed )
85 [ # # ]: 0 : throw DisposedException();
86 : :
87 : : OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" );
88 [ # # ]: 0 : if ( _rURL.Complete == getFeatureURL().Complete )
89 [ # # ]: 0 : if ( _rxControl.is() )
90 : : {
91 : 0 : m_aStatusListeners.addInterface( _rxControl );
92 : 0 : newStatusListener( _rxControl );
93 : : }
94 : 0 : }
95 : :
96 : : //--------------------------------------------------------------------
97 : 0 : void SAL_CALL ORichTextFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& /*_rURL*/ ) throw (RuntimeException)
98 : : {
99 : 0 : m_aStatusListeners.removeInterface( _rxControl );
100 : 0 : }
101 : :
102 : : //--------------------------------------------------------------------
103 : 0 : void ORichTextFeatureDispatcher::invalidate()
104 : : {
105 : 0 : invalidateFeatureState_Broadcast();
106 : 0 : }
107 : :
108 : : //--------------------------------------------------------------------
109 : 0 : FeatureStateEvent ORichTextFeatureDispatcher::buildStatusEvent() const
110 : : {
111 : 0 : FeatureStateEvent aEvent;
112 : 0 : aEvent.IsEnabled = sal_False;
113 [ # # ][ # # ]: 0 : aEvent.Source = *const_cast< ORichTextFeatureDispatcher* >( this );
114 : 0 : aEvent.FeatureURL = getFeatureURL();
115 : 0 : aEvent.Requery = sal_False;
116 : 0 : return aEvent;
117 : : }
118 : :
119 : : //--------------------------------------------------------------------
120 : 0 : void ORichTextFeatureDispatcher::invalidateFeatureState_Broadcast()
121 : : {
122 [ # # ]: 0 : FeatureStateEvent aEvent( buildStatusEvent() );
123 [ # # ]: 0 : ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() );
124 [ # # ]: 0 : while ( aIter.hasMoreElements() )
125 [ # # ][ # # ]: 0 : doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
[ # # ][ # # ]
[ # # ]
126 : 0 : }
127 : :
128 : : //--------------------------------------------------------------------
129 : 0 : void ORichTextFeatureDispatcher::newStatusListener( const Reference< XStatusListener >& _rxListener )
130 : : {
131 [ # # ]: 0 : doNotify( _rxListener, buildStatusEvent() );
132 : 0 : }
133 : :
134 : : //--------------------------------------------------------------------
135 : 0 : void ORichTextFeatureDispatcher::doNotify( const Reference< XStatusListener >& _rxListener, const FeatureStateEvent& _rEvent ) const SAL_THROW(())
136 : : {
137 : : OSL_PRECOND( _rxListener.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
138 [ # # ]: 0 : if ( _rxListener.is() )
139 : : {
140 : : try
141 : : {
142 [ # # ][ # # ]: 0 : _rxListener->statusChanged( _rEvent );
143 : : }
144 : 0 : catch( const Exception& )
145 : : {
146 : : OSL_FAIL( "ORichTextFeatureDispatcher::doNotify: caught an exception!" );
147 : : }
148 : : }
149 [ # # ]: 0 : }
150 : :
151 : : //........................................................................
152 : : } // namespace frm
153 : : //........................................................................
154 : :
155 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|