LibreOffice Module chart2 (master) 1
CommandDispatch.cxx
Go to the documentation of this file.
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#include "CommandDispatch.hxx"
21#include <com/sun/star/util/URLTransformer.hpp>
23
24using namespace ::com::sun::star;
25
26using ::com::sun::star::uno::Reference;
27using ::com::sun::star::uno::Sequence;
28
29namespace chart
30{
31
33 const Reference< uno::XComponentContext > & xContext ) :
34 m_xContext( xContext )
35{
36}
37
39{}
40
42{}
43
44// ____ WeakComponentImplHelperBase ____
46void CommandDispatch::disposing(std::unique_lock<std::mutex>& rGuard)
47{
48 Reference< uno::XInterface > xEventSource(static_cast< cppu::OWeakObject* >( this ));
49 for( auto& rElement : m_aListeners )
50 rElement.second.disposeAndClear( rGuard, xEventSource );
51 m_aListeners.clear();
52}
53
54// ____ XDispatch ____
55void SAL_CALL CommandDispatch::dispatch( const util::URL& /* URL */, const Sequence< beans::PropertyValue >& /* Arguments */ )
56{}
57
59{
60 {
61 std::unique_lock g(m_aMutex);
62 tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
63 if( aIt == m_aListeners.end())
64 {
65 aIt = m_aListeners.emplace(
66 std::piecewise_construct,
67 std::forward_as_tuple(URL.Complete),
68 std::forward_as_tuple()).first;
69 }
70 assert( aIt != m_aListeners.end());
71
72 aIt->second.addInterface( g, Control );
73 }
74 fireStatusEvent( URL.Complete, Control );
75}
76
78{
79 std::unique_lock g(m_aMutex);
80 tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
81 if( aIt != m_aListeners.end())
82 (*aIt).second.removeInterface( g, Control );
83}
84
85// ____ XModifyListener ____
86void SAL_CALL CommandDispatch::modified( const lang::EventObject& /* aEvent */ )
87{
88 fireAllStatusEvents( nullptr );
89}
90
91// ____ XEventListener (base of XModifyListener) ____
92void SAL_CALL CommandDispatch::disposing( const lang::EventObject& /* Source */ )
93{}
94
96 const css::uno::Reference< css::frame::XStatusListener > & xSingleListener )
97{
98 fireStatusEvent( OUString(), xSingleListener );
99}
100
102 const OUString & rURL,
103 const uno::Any & rState,
104 bool bEnabled,
105 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */)
106{
107 // prepare event to send
108 util::URL aURL;
109 aURL.Complete = rURL;
110 if( !m_xURLTransformer.is())
111 {
112 m_xURLTransformer.set( util::URLTransformer::create(m_xContext) );
113 }
114 m_xURLTransformer->parseStrict( aURL );
115
116 frame::FeatureStateEvent aEventToSend(
117 static_cast< cppu::OWeakObject* >( this ), // Source
118 aURL, // FeatureURL
119 OUString(), // FeatureDescriptor
120 bEnabled, // IsEnabled
121 false, // Requery
122 rState // State
123 );
124
125 // send event either to single listener or all registered ones
126 if( xSingleListener.is())
127 xSingleListener->statusChanged( aEventToSend );
128 else
129 {
130 tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ));
131 if( aIt != m_aListeners.end())
132 {
133 std::unique_lock g(m_aMutex);
134 aIt->second.notifyEach(g, &css::frame::XStatusListener::statusChanged, aEventToSend);
135 }
136 }
137}
138
139} // namespace chart
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< uno::XComponentContext > m_xContext
css::uno::Reference< css::uno::XComponentContext > m_xContext
CommandDispatch(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual void fireStatusEvent(const OUString &rURL, const css::uno::Reference< css::frame::XStatusListener > &xSingleListener)=0
sends a status event for a specific command to all registered listeners or only the one given when se...
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &Control, const css::util::URL &URL) override
void fireAllStatusEvents(const css::uno::Reference< css::frame::XStatusListener > &xSingleListener)
calls fireStatusEvent( OUString, xSingleListener )
virtual ~CommandDispatch() override
void fireStatusEventForURL(const OUString &rURL, const css::uno::Any &rState, bool bEnabled, const css::uno::Reference< css::frame::XStatusListener > &xSingleListener)
sends a status event for a specific command to all registered listeners or only the one given when se...
virtual void disposing(std::unique_lock< std::mutex > &rGuard) override
is called when this is disposed
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &Control, const css::util::URL &URL) override
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL dispatch(const css::util::URL &URL, const css::uno::Sequence< css::beans::PropertyValue > &Arguments) override
css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer
URL aURL