Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / inc / CommandDispatchContainer.hxx
blob72c2daaa93672022d7561e97a1e3acebd6b1d97c
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 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_COMMANDDISPATCHCONTAINER_HXX
20 #define INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_COMMANDDISPATCHCONTAINER_HXX
22 #include <cppuhelper/weakref.hxx>
24 #include <set>
25 #include <map>
26 #include <vector>
28 namespace com { namespace sun { namespace star { namespace frame { class XController; } } } }
29 namespace com { namespace sun { namespace star { namespace frame { class XDispatch; } } } }
30 namespace com { namespace sun { namespace star { namespace frame { class XModel; } } } }
31 namespace com { namespace sun { namespace star { namespace frame { struct DispatchDescriptor; } } } }
32 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
33 namespace com { namespace sun { namespace star { namespace util { struct URL; } } } }
35 namespace chart
38 class DrawCommandDispatch;
39 class ShapeController;
41 /** @HTML
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:
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>
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>
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>
67 class CommandDispatchContainer
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 );
76 void setModel(
77 const css::uno::Reference< css::frame::XModel > & xModel );
79 /** Set a chart dispatcher that is used for all commands contained in
80 rChartCommands
82 void setChartDispatch(
83 const css::uno::Reference< css::frame::XDispatch >& rChartDispatch,
84 const std::set< OUString > & rChartCommands );
86 /** Returns the dispatch that is able to do the command given in rURL, if
87 implemented here. If the URL is not implemented here, it should be
88 checked whether the command is one of the commands given via
89 the setChartDispatch() method. If so, call the chart dispatch.
91 <p>If all this fails, return an empty dispatch.</p>
93 css::uno::Reference< css::frame::XDispatch > getDispatchForURL(
94 const css::util::URL & rURL );
96 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > getDispatchesForURLs(
97 const css::uno::Sequence< css::frame::DispatchDescriptor > & aDescriptors );
99 void DisposeAndClear();
101 static css::uno::Reference< css::frame::XDispatch >
102 getContainerDispatchForURL(
103 const css::uno::Reference< css::frame::XController > & xChartController,
104 const css::util::URL & rURL );
106 void setDrawCommandDispatch( DrawCommandDispatch* pDispatch );
107 DrawCommandDispatch* getDrawCommandDispatch() { return m_pDrawCommandDispatch; }
108 void setShapeController( ShapeController* pController );
109 ShapeController* getShapeController() { return m_pShapeController; }
111 private:
112 typedef
113 std::map< OUString,
114 css::uno::Reference< css::frame::XDispatch > >
115 tDispatchMap;
117 typedef
118 std::vector< css::uno::Reference< css::frame::XDispatch > > tDisposeVector;
120 mutable tDispatchMap m_aCachedDispatches;
121 mutable tDisposeVector m_aToBeDisposedDispatches;
123 css::uno::Reference< css::uno::XComponentContext > m_xContext;
124 css::uno::WeakReference< css::frame::XModel > m_xModel;
126 css::uno::Reference< css::frame::XDispatch > m_xChartDispatcher;
127 std::set< OUString > m_aChartCommands;
129 DrawCommandDispatch* m_pDrawCommandDispatch;
130 ShapeController* m_pShapeController;
133 } // namespace chart
135 // INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_COMMANDDISPATCHCONTAINER_HXX
136 #endif
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */