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