Debian Codegraph @

chart2/source/controller/inc/CommandDispatch.hxx

raw
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 #pragma once
20
21 #include <comphelper/compbase.hxx>
22 #include <comphelper/interfacecontainer4.hxx>
23 #include <com/sun/star/frame/XDispatch.hpp>
24 #include <com/sun/star/util/XModifyListener.hpp>
25
26 #include <map>
27
28 namespace com::sun::star::uno { class XComponentContext; }
29 namespace com::sun::star::util { class XURLTransformer; }
30
31 namespace chart
32 {
33
34 namespace impl
35 {
36 typedef ::comphelper::WeakComponentImplHelper<
37 css::frame::XDispatch,
38 css::util::XModifyListener >
39 CommandDispatch_Base;
40 }
41
42 /** This is the base class for an XDispatch.
43 */
44 class CommandDispatch : public impl::CommandDispatch_Base
45 {
46 public:
47 explicit CommandDispatch( const css::uno::Reference< css::uno::XComponentContext > & xContext );
48 virtual ~CommandDispatch() override;
49
50 // late initialisation, especially for adding as listener
51 virtual void initialize();
52
53 protected:
54 /** sends a status event for a specific command to all registered listeners
55 or only the one given when set.
56
57 This method should be overridden. The implementation should call
58 fireStatusEventForURL and pass the xSingleListener argument to this
59 method unchanged.
60
61 @param rURL
62 If empty, all available status events must be fired, otherwise only
63 the one for the given command.
64
65 @param xSingleListener
66 If set, the event is only sent to this listener rather than to all
67 registered ones. Whenever a listener adds itself, this method is
68 called with this parameter set to give an initial state.
69 */
70 virtual void fireStatusEvent(
71 const OUString & rURL,
72 const css::uno::Reference< css::frame::XStatusListener > & xSingleListener ) = 0;
73
74 /** calls fireStatusEvent( OUString, xSingleListener )
75 */
76 void fireAllStatusEvents(
77 const css::uno::Reference< css::frame::XStatusListener > & xSingleListener );
78
79 /** sends a status event for a specific command to all registered listeners
80 or only the one given when set.
81
82 @param xSingleListener
83 If set, the event is only sent to this listener rather than to all
84 registered ones. Whenever a listener adds itself, this method is
85 called with this parameter set to give an initial state.
86 */
87 void fireStatusEventForURL(
88 const OUString & rURL,
89 const css::uno::Any & rState,
90 bool bEnabled,
91 const css::uno::Reference< css::frame::XStatusListener > & xSingleListener );
92
93 // ____ XDispatch ____
94 virtual void SAL_CALL dispatch(
95 const css::util::URL& URL,
96 const css::uno::Sequence< css::beans::PropertyValue >& Arguments ) override;
97 virtual void SAL_CALL addStatusListener(
98 const css::uno::Reference< css::frame::XStatusListener >& Control,
99 const css::util::URL& URL ) override;
100 virtual void SAL_CALL removeStatusListener(
101 const css::uno::Reference< css::frame::XStatusListener >& Control,
102 const css::util::URL& URL ) override;
103
104 // ____ WeakComponentImplHelperBase ____
105 /// is called when this is disposed
106 virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
107
108 // ____ XModifyListener ____
109 virtual void SAL_CALL modified(
110 const css::lang::EventObject& aEvent ) override;
111
112 // ____ XEventListener (base of XModifyListener) ____
113 virtual void SAL_CALL disposing(
114 const css::lang::EventObject& Source ) override;
115
116 private:
117 css::uno::Reference< css::uno::XComponentContext > m_xContext;
118 css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer;
119
120 typedef std::map< OUString, ::comphelper::OInterfaceContainerHelper4<css::frame::XStatusListener> >
121 tListenerMap;
122
123 tListenerMap m_aListeners;
124
125 };
126
127 } // namespace chart
128
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */