tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / main / CommandDispatch.cxx
blob2cb25f68d5bf6001da8f8a2e4c494f4cdffa5cee
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 "CommandDispatch.hxx"
21 #include <com/sun/star/util/URLTransformer.hpp>
23 using namespace ::com::sun::star;
25 using ::com::sun::star::uno::Reference;
26 using ::com::sun::star::uno::Sequence;
28 namespace chart
31 CommandDispatch::CommandDispatch(
32 const Reference< uno::XComponentContext > & xContext ) :
33 m_xContext( xContext )
37 CommandDispatch::~CommandDispatch()
40 void CommandDispatch::initialize()
43 // ____ WeakComponentImplHelperBase ____
44 /// is called when this is disposed
45 void CommandDispatch::disposing(std::unique_lock<std::mutex>& rGuard)
47 Reference< uno::XInterface > xEventSource(static_cast< cppu::OWeakObject* >( this ));
48 for( auto& rElement : m_aListeners )
49 rElement.second.disposeAndClear( rGuard, xEventSource );
50 m_aListeners.clear();
53 // ____ XDispatch ____
54 void SAL_CALL CommandDispatch::dispatch( const util::URL& /* URL */, const Sequence< beans::PropertyValue >& /* Arguments */ )
57 void SAL_CALL CommandDispatch::addStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
60 std::unique_lock g(m_aMutex);
61 tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
62 if( aIt == m_aListeners.end())
64 aIt = m_aListeners.emplace(
65 std::piecewise_construct,
66 std::forward_as_tuple(URL.Complete),
67 std::forward_as_tuple()).first;
69 assert( aIt != m_aListeners.end());
71 aIt->second.addInterface( g, Control );
73 fireStatusEvent( URL.Complete, Control );
76 void SAL_CALL CommandDispatch::removeStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
78 std::unique_lock g(m_aMutex);
79 tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
80 if( aIt != m_aListeners.end())
81 (*aIt).second.removeInterface( g, Control );
84 // ____ XModifyListener ____
85 void SAL_CALL CommandDispatch::modified( const lang::EventObject& /* aEvent */ )
87 fireAllStatusEvents( nullptr );
90 // ____ XEventListener (base of XModifyListener) ____
91 void SAL_CALL CommandDispatch::disposing( const lang::EventObject& /* Source */ )
94 void CommandDispatch::fireAllStatusEvents(
95 const css::uno::Reference< css::frame::XStatusListener > & xSingleListener )
97 fireStatusEvent( OUString(), xSingleListener );
100 void CommandDispatch::fireStatusEventForURL(
101 const OUString & rURL,
102 const uno::Any & rState,
103 bool bEnabled,
104 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */)
106 // prepare event to send
107 util::URL aURL;
108 aURL.Complete = rURL;
109 if( !m_xURLTransformer.is())
111 m_xURLTransformer.set( util::URLTransformer::create(m_xContext) );
113 m_xURLTransformer->parseStrict( aURL );
115 frame::FeatureStateEvent aEventToSend(
116 static_cast< cppu::OWeakObject* >( this ), // Source
117 aURL, // FeatureURL
118 OUString(), // FeatureDescriptor
119 bEnabled, // IsEnabled
120 false, // Requery
121 rState // State
124 // send event either to single listener or all registered ones
125 if( xSingleListener.is())
126 xSingleListener->statusChanged( aEventToSend );
127 else
129 tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ));
130 if( aIt != m_aListeners.end())
132 std::unique_lock g(m_aMutex);
133 aIt->second.notifyEach(g, &css::frame::XStatusListener::statusChanged, aEventToSend);
138 } // namespace chart
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */