Debian Codegraph @

chart2/source/controller/inc/CommandDispatchContainer.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 <unotools/weakref.hxx>
22 #include <o3tl/sorted_vector.hxx>
23
24 #include "ControllerCommandDispatch.hxx"
25
26 #include <map>
27 #include <vector>
28
29 namespace com::sun::star::frame { class XController; }
30 namespace com::sun::star::frame { class XDispatch; }
31 namespace com::sun::star::frame { struct DispatchDescriptor; }
32 namespace com::sun::star::uno { class XComponentContext; }
33 namespace com::sun::star::util { struct URL; }
34
35 namespace chart
36 {
37 class ChartModel;
38 class DrawCommandDispatch;
39 class ShapeController;
40
41 /** @HTML
42
43 Helper class for implementing the <code>XDispatchProvider</code> interface
44 of the ChartController. This class handles all commands to queryDispatch and
45 queryDispatches in the following way:
46
47 <ul>
48 <li>Check if there is a cached <code>XDispatch</code> for a given command.
49 If so, use it.</li>
50 <li>Check if the command is handled by this class, e.g. Undo. If so,
51 return a corresponding <code>XDispatch</code> implementation, and cache
52 this implementation for later use</li>
53 <li>Otherwise send the command to the chart dispatch provider, if it
54 can handle this dispatch (determined by the list of commands given in
55 <code>setChartDispatch()</code>).</li>
56 </ul>
57
58 <p>The <code>XDispatch</code>Provider is designed to return different
59 <code>XDispatch</code> implementations for each command. This class here
60 decides which implementation to use for which command.</p>
61
62 <p>As most commands need much information of the controller and are
63 implemented there, the controller handles most of the commands itself (it
64 also implements <code>XDispatch</code>). Therefore it is set here as
65 chart dispatch.</p>
66 */
67 class CommandDispatchContainer
68 {
69 public:
70 // note: the chart dispatcher should be removed when all commands are
71 // handled by other dispatchers. (Chart is currently the controller
72 // itself)
73 explicit CommandDispatchContainer(
74 const css::uno::Reference< css::uno::XComponentContext > & xContext );
75 ~CommandDispatchContainer();
76
77 void setModel(
78 const rtl::Reference<::chart::ChartModel> & xModel );
79
80 /** Set a chart dispatcher that is used for all commands contained in
81 rChartCommands
82 */
83 void setChartDispatch(
84 const rtl::Reference< ControllerCommandDispatch >& rChartDispatch,
85 const o3tl::sorted_vector< std::u16string_view > & rChartCommands );
86
87 /** Returns the dispatch that is able to do the command given in rURL, if
88 implemented here. If the URL is not implemented here, it should be
89 checked whether the command is one of the commands given via
90 the setChartDispatch() method. If so, call the chart dispatch.
91
92 <p>If all this fails, return an empty dispatch.</p>
93 */
94 css::uno::Reference< css::frame::XDispatch > getDispatchForURL(
95 const css::util::URL & rURL );
96
97 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > getDispatchesForURLs(
98 const css::uno::Sequence< css::frame::DispatchDescriptor > & aDescriptors );
99
100 void DisposeAndClear();
101
102 static css::uno::Reference< css::frame::XDispatch >
103 getContainerDispatchForURL(
104 const css::uno::Reference< css::frame::XController > & xChartController,
105 const css::util::URL & rURL );
106
107 const ControllerCommandDispatch* getChartDispatcher() const { return m_xChartDispatcher.get(); }
108
109 void setDrawCommandDispatch( DrawCommandDispatch* pDispatch );
110 DrawCommandDispatch* getDrawCommandDispatch() { return m_pDrawCommandDispatch; }
111 void setShapeController( ShapeController* pController );
112 ShapeController* getShapeController() { return m_pShapeController; }
113
114 private:
115 typedef
116 std::map< OUString,
117 css::uno::Reference< css::frame::XDispatch > >
118 tDispatchMap;
119
120 typedef
121 std::vector< css::uno::Reference< css::frame::XDispatch > > tDisposeVector;
122
123 mutable tDispatchMap m_aCachedDispatches;
124 mutable tDisposeVector m_aToBeDisposedDispatches;
125
126 css::uno::Reference< css::uno::XComponentContext > m_xContext;
127 unotools::WeakReference< ::chart::ChartModel > m_xModel;
128
129 rtl::Reference<ControllerCommandDispatch> m_xChartDispatcher;
130 o3tl::sorted_vector<std::u16string_view> m_aAdditionalChartCommands;
131
132 DrawCommandDispatch* m_pDrawCommandDispatch;
133 ShapeController* m_pShapeController;
134 };
135
136 } // namespace chart
137
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */