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