Line data Source code
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 : #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_COMMANDDISPATCHCONTAINER_HXX
20 : #define INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_COMMANDDISPATCHCONTAINER_HXX
21 :
22 : #include <com/sun/star/uno/XComponentContext.hpp>
23 : #include <com/sun/star/frame/XDispatch.hpp>
24 : #include <com/sun/star/frame/XModel.hpp>
25 : #include <com/sun/star/frame/DispatchDescriptor.hpp>
26 :
27 : #include <cppuhelper/weakref.hxx>
28 : #include <cppuhelper/interfacecontainer.hxx>
29 :
30 : #include <set>
31 : #include <map>
32 :
33 : namespace chart
34 : {
35 :
36 : class ChartController;
37 : class DrawCommandDispatch;
38 : class ShapeController;
39 :
40 : /** @HTML
41 :
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:
45 :
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>
56 :
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>
60 :
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>
65 : */
66 0 : class CommandDispatchContainer
67 : {
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 ::com::sun::star::uno::Reference<
74 : ::com::sun::star::uno::XComponentContext > & xContext,
75 : ChartController* pController );
76 :
77 : void setModel(
78 : const ::com::sun::star::uno::Reference<
79 : ::com::sun::star::frame::XModel > & xModel );
80 :
81 : /** Set a chart dispatcher that is used for all commands contained in
82 : rChartCommands
83 : */
84 : void setChartDispatch(
85 : const ::com::sun::star::uno::Reference<
86 : ::com::sun::star::frame::XDispatch > xChartDispatch,
87 : const ::std::set< OUString > & rChartCommands );
88 :
89 : /** Returns the dispatch that is able to do the command given in rURL, if
90 : implemented here. If the URL is not implemented here, it should be
91 : checked whether the command is one of the commands given via
92 : the setChartDispatch() method. If so, call the chart dispatch.
93 :
94 : <p>If all this fails, return an empty dispatch.</p>
95 : */
96 : ::com::sun::star::uno::Reference<
97 : ::com::sun::star::frame::XDispatch > getDispatchForURL(
98 : const ::com::sun::star::util::URL & rURL );
99 :
100 : ::com::sun::star::uno::Sequence<
101 : ::com::sun::star::uno::Reference<
102 : ::com::sun::star::frame::XDispatch > > getDispatchesForURLs(
103 : const ::com::sun::star::uno::Sequence<
104 : ::com::sun::star::frame::DispatchDescriptor > & aDescriptors );
105 :
106 : void DisposeAndClear();
107 :
108 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >
109 : getContainerDispatchForURL(
110 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > & xChartController,
111 : const ::com::sun::star::util::URL & rURL );
112 :
113 : void setDrawCommandDispatch( DrawCommandDispatch* pDispatch );
114 0 : DrawCommandDispatch* getDrawCommandDispatch() { return m_pDrawCommandDispatch; }
115 : void setShapeController( ShapeController* pController );
116 0 : ShapeController* getShapeController() { return m_pShapeController; }
117 :
118 : private:
119 : typedef
120 : ::std::map< OUString,
121 : ::com::sun::star::uno::Reference<
122 : ::com::sun::star::frame::XDispatch > >
123 : tDispatchMap;
124 :
125 : typedef
126 : ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > tDisposeVector;
127 :
128 : mutable tDispatchMap m_aCachedDispatches;
129 : mutable tDisposeVector m_aToBeDisposedDispatches;
130 :
131 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
132 : ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > m_xModel;
133 :
134 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > m_xChartDispatcher;
135 : ::std::set< OUString > m_aChartCommands;
136 :
137 : ::std::set< OUString > m_aContainerDocumentCommands;
138 :
139 : ChartController* m_pChartController;
140 : DrawCommandDispatch* m_pDrawCommandDispatch;
141 : ShapeController* m_pShapeController;
142 : };
143 :
144 : } // namespace chart
145 :
146 : // INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_COMMANDDISPATCHCONTAINER_HXX
147 : #endif
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|