Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "CommandDispatch.hxx"
22 : : #include "CommonFunctors.hxx"
23 : : #include "macros.hxx"
24 : : #include <com/sun/star/util/URLTransformer.hpp>
25 : :
26 : : #include <algorithm>
27 : : #include <functional>
28 : :
29 : : using namespace ::com::sun::star;
30 : :
31 : : using ::com::sun::star::uno::Reference;
32 : : using ::com::sun::star::uno::Sequence;
33 : : using ::rtl::OUString;
34 : :
35 : : namespace
36 : : {
37 : : template< class Map >
38 : 0 : struct lcl_DisposeAndClearAndDeleteMapElement :
39 : : public ::std::unary_function< typename Map::value_type, void >
40 : : {
41 : 0 : lcl_DisposeAndClearAndDeleteMapElement( const Reference< uno::XInterface > & xEventSource ) :
42 : 0 : m_aEvent( xEventSource )
43 : 0 : {}
44 : 0 : void operator() ( typename Map::value_type & rElement )
45 : : {
46 [ # # ]: 0 : if( rElement.second )
47 : : {
48 : 0 : rElement.second->disposeAndClear( m_aEvent );
49 [ # # ]: 0 : delete rElement.second;
50 : : }
51 : 0 : }
52 : : private:
53 : : lang::EventObject m_aEvent;
54 : : };
55 : :
56 : : template< class Map >
57 : 0 : void lcl_DisposeAndClearAndDeleteAllMapElements(
58 : : Map & rMap,
59 : : const Reference< uno::XInterface > & xEventSource )
60 : : {
61 [ # # ][ # # ]: 0 : ::std::for_each( rMap.begin(), rMap.end(),
62 : : lcl_DisposeAndClearAndDeleteMapElement< Map >( xEventSource ));
63 : 0 : }
64 : :
65 : : } // anonymous namespace
66 : :
67 : : namespace chart
68 : : {
69 : :
70 : 170 : CommandDispatch::CommandDispatch(
71 : : const Reference< uno::XComponentContext > & xContext ) :
72 : : impl::CommandDispatch_Base( m_aMutex ),
73 [ + - ]: 170 : m_xContext( xContext )
74 : : {
75 : 170 : }
76 : :
77 [ + - ]: 170 : CommandDispatch::~CommandDispatch()
78 [ - + ]: 170 : {}
79 : :
80 : 68 : void CommandDispatch::initialize()
81 : 68 : {}
82 : :
83 : : // ____ WeakComponentImplHelperBase ____
84 : : /// is called when this is disposed
85 : 0 : void SAL_CALL CommandDispatch::disposing()
86 : : {
87 [ # # ]: 0 : lcl_DisposeAndClearAndDeleteAllMapElements( m_aListeners, static_cast< cppu::OWeakObject* >( this ));
88 : 0 : m_aListeners.clear();
89 : 0 : }
90 : :
91 : : // ____ XDispatch ____
92 : 0 : void SAL_CALL CommandDispatch::dispatch( const util::URL& /* URL */, const Sequence< beans::PropertyValue >& /* Arguments */ )
93 : : throw (uno::RuntimeException)
94 : 0 : {}
95 : :
96 : 986 : void SAL_CALL CommandDispatch::addStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
97 : : throw (uno::RuntimeException)
98 : : {
99 [ + - ]: 986 : tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
100 [ + - ]: 986 : if( aIt == m_aListeners.end())
101 : : {
102 : : aIt = m_aListeners.insert(
103 : 986 : m_aListeners.begin(),
104 [ + - ][ + - ]: 986 : tListenerMap::value_type( URL.Complete, new ::cppu::OInterfaceContainerHelper( m_aMutex )));
[ + - ]
105 : : }
106 : : OSL_ASSERT( aIt != m_aListeners.end());
107 : :
108 [ + - ]: 986 : aIt->second->addInterface( Control );
109 [ + - ]: 986 : fireStatusEvent( URL.Complete, Control );
110 : 986 : }
111 : :
112 : 986 : void SAL_CALL CommandDispatch::removeStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
113 : : throw (uno::RuntimeException)
114 : : {
115 [ + - ]: 986 : tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
116 [ + - ]: 986 : if( aIt != m_aListeners.end())
117 [ + - ]: 986 : (*aIt).second->removeInterface( Control );
118 : 986 : }
119 : :
120 : : // ____ XModifyListener ____
121 : 4109 : void SAL_CALL CommandDispatch::modified( const lang::EventObject& /* aEvent */ )
122 : : throw (uno::RuntimeException)
123 : : {
124 [ + - ]: 4109 : fireAllStatusEvents( 0 );
125 : 4109 : }
126 : :
127 : : // ____ XEventListener (base of XModifyListener) ____
128 : 0 : void SAL_CALL CommandDispatch::disposing( const lang::EventObject& /* Source */ )
129 : : throw (uno::RuntimeException)
130 : 0 : {}
131 : :
132 : 4858 : void CommandDispatch::fireAllStatusEvents(
133 : : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener )
134 : : {
135 [ + - ]: 4858 : fireStatusEvent( OUString(), xSingleListener );
136 : 4858 : }
137 : :
138 : 252710 : void CommandDispatch::fireStatusEventForURL(
139 : : const OUString & rURL,
140 : : const uno::Any & rState,
141 : : bool bEnabled,
142 : : const Reference< frame::XStatusListener > & xSingleListener, /* = 0 */
143 : : const OUString & rFeatureDescriptor /* = OUString() */ )
144 : : {
145 : : // prepare event to send
146 : 252710 : util::URL aURL;
147 : 252710 : aURL.Complete = rURL;
148 [ + + ]: 252710 : if( !m_xURLTransformer.is())
149 : : {
150 [ + - ][ + - ]: 136 : m_xURLTransformer.set( util::URLTransformer::create(m_xContext) );
151 : : }
152 [ + - ][ + - ]: 252710 : m_xURLTransformer->parseStrict( aURL );
153 : :
154 : : frame::FeatureStateEvent aEventToSend(
155 : : static_cast< cppu::OWeakObject* >( this ), // Source
156 : : aURL, // FeatureURL
157 : : rFeatureDescriptor, // FeatureDescriptor
158 : : bEnabled, // IsEnabled
159 : : false, // Requery
160 : : rState // State
161 [ + - ][ + - ]: 252710 : );
[ # # ]
162 : :
163 : : // send event either to single listener or all registered ones
164 [ + + ]: 252710 : if( xSingleListener.is())
165 [ + - ][ + - ]: 986 : xSingleListener->statusChanged( aEventToSend );
166 : : else
167 : : {
168 [ + - ]: 251724 : tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ));
169 [ + + ]: 251724 : if( aIt != m_aListeners.end())
170 : : {
171 [ + - ]: 29669 : if( aIt->second )
172 : : {
173 [ + - ]: 29669 : ::cppu::OInterfaceIteratorHelper aIntfIt( *((*aIt).second) );
174 : :
175 [ + + ]: 59338 : while( aIntfIt.hasMoreElements())
176 : : {
177 [ + - ][ + - ]: 29669 : Reference< frame::XStatusListener > xListener( aIntfIt.next(), uno::UNO_QUERY );
178 : : try
179 : : {
180 [ + - ]: 29669 : if( xListener.is())
181 [ + - ][ + - ]: 29669 : xListener->statusChanged( aEventToSend );
182 : : }
183 [ # # ]: 0 : catch( const uno::Exception & ex )
184 : : {
185 : : ASSERT_EXCEPTION( ex );
186 : : }
187 [ + - ]: 281393 : }
188 : : }
189 : : }
190 [ + - ]: 252710 : }
191 : 252710 : }
192 : :
193 : :
194 : :
195 : : } // namespace chart
196 : :
197 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|