1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "CommandDispatch.hxx"
21 #include <com/sun/star/util/URLTransformer.hpp>
22 #include <tools/diagnose_ex.h>
24 using namespace ::com::sun::star
;
26 using ::com::sun::star::uno::Reference
;
27 using ::com::sun::star::uno::Sequence
;
32 void lcl_DisposeAndClearAndDeleteAllMapElements(
34 const Reference
< uno::XInterface
> & xEventSource
)
36 for( const auto& rElement
: rMap
)
40 rElement
.second
->disposeAndClear( xEventSource
);
41 delete rElement
.second
;
46 } // anonymous namespace
51 CommandDispatch::CommandDispatch(
52 const Reference
< uno::XComponentContext
> & xContext
) :
53 impl::CommandDispatch_Base( m_aMutex
),
54 m_xContext( xContext
)
58 CommandDispatch::~CommandDispatch()
61 void CommandDispatch::initialize()
64 // ____ WeakComponentImplHelperBase ____
65 /// is called when this is disposed
66 void SAL_CALL
CommandDispatch::disposing()
68 lcl_DisposeAndClearAndDeleteAllMapElements( m_aListeners
, static_cast< cppu::OWeakObject
* >( this ));
72 // ____ XDispatch ____
73 void SAL_CALL
CommandDispatch::dispatch( const util::URL
& /* URL */, const Sequence
< beans::PropertyValue
>& /* Arguments */ )
76 void SAL_CALL
CommandDispatch::addStatusListener( const Reference
< frame::XStatusListener
>& Control
, const util::URL
& URL
)
78 tListenerMap::iterator
aIt( m_aListeners
.find( URL
.Complete
));
79 if( aIt
== m_aListeners
.end())
81 aIt
= m_aListeners
.insert(
83 tListenerMap::value_type( URL
.Complete
, new ::comphelper::OInterfaceContainerHelper2( m_aMutex
)));
85 OSL_ASSERT( aIt
!= m_aListeners
.end());
87 aIt
->second
->addInterface( Control
);
88 fireStatusEvent( URL
.Complete
, Control
);
91 void SAL_CALL
CommandDispatch::removeStatusListener( const Reference
< frame::XStatusListener
>& Control
, const util::URL
& URL
)
93 tListenerMap::iterator
aIt( m_aListeners
.find( URL
.Complete
));
94 if( aIt
!= m_aListeners
.end())
95 (*aIt
).second
->removeInterface( Control
);
98 // ____ XModifyListener ____
99 void SAL_CALL
CommandDispatch::modified( const lang::EventObject
& /* aEvent */ )
101 fireAllStatusEvents( nullptr );
104 // ____ XEventListener (base of XModifyListener) ____
105 void SAL_CALL
CommandDispatch::disposing( const lang::EventObject
& /* Source */ )
108 void CommandDispatch::fireAllStatusEvents(
109 const css::uno::Reference
< css::frame::XStatusListener
> & xSingleListener
)
111 fireStatusEvent( OUString(), xSingleListener
);
114 void CommandDispatch::fireStatusEventForURL(
115 const OUString
& rURL
,
116 const uno::Any
& rState
,
118 const Reference
< frame::XStatusListener
> & xSingleListener
/* = 0 */)
120 // prepare event to send
122 aURL
.Complete
= rURL
;
123 if( !m_xURLTransformer
.is())
125 m_xURLTransformer
.set( util::URLTransformer::create(m_xContext
) );
127 m_xURLTransformer
->parseStrict( aURL
);
129 frame::FeatureStateEvent
aEventToSend(
130 static_cast< cppu::OWeakObject
* >( this ), // Source
132 OUString(), // FeatureDescriptor
133 bEnabled
, // IsEnabled
138 // send event either to single listener or all registered ones
139 if( xSingleListener
.is())
140 xSingleListener
->statusChanged( aEventToSend
);
143 tListenerMap::iterator
aIt( m_aListeners
.find( aURL
.Complete
));
144 if( aIt
!= m_aListeners
.end())
148 ::comphelper::OInterfaceIteratorHelper2
aIntfIt( *((*aIt
).second
) );
150 while( aIntfIt
.hasMoreElements())
152 Reference
< frame::XStatusListener
> xListener( aIntfIt
.next(), uno::UNO_QUERY
);
156 xListener
->statusChanged( aEventToSend
);
158 catch( const uno::Exception
& )
160 DBG_UNHANDLED_EXCEPTION("chart2");
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */