1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef CHART2_COMMANDDISPATCHCONTAINER_HXX
24 #define CHART2_COMMANDDISPATCHCONTAINER_HXX
25 
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/frame/XDispatch.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/frame/DispatchDescriptor.hpp>
30 
31 #include <cppuhelper/weakref.hxx>
32 #include <cppuhelper/interfacecontainer.hxx>
33 
34 #include <set>
35 #include <map>
36 
37 namespace chart
38 {
39 
40 class ChartController;
41 class DrawCommandDispatch;
42 class ShapeController;
43 
44 /** @HTML
45 
46     Helper class for implementing the <code>XDispatchProvider</code> interface
47     of the ChartController. This class handles all commands to queryDispatch and
48     queryDispatches in the following way:
49 
50     <ul>
51       <li>Check if there is a cached <code>XDispatch</code> for a given command.
52         If so, use it.</li>
53       <li>Check if the command is handled by this class, e.g. Undo.  If so,
54         return a corresponding <code>XDispatch</code> implementation, and cache
55         this implementation for later use</li>
56       <li>Otherwise send the command to the chart dispatch provider, if it
57         can handle this dispatch (determined by the list of commands given in
58         <code>setChartDispatch()</code>).</li>
59     </ul>
60 
61     <p>The <code>XDispatch</code>Provider is designed to return different
62     <code>XDispatch</code> implementations for each command.  This class here
63     decides which implementation to use for which command.</p>
64 
65     <p>As most commands need much information of the controller and are
66     implemented there, the controller handles most of the commands itself (it
67     also implements <code>XDispatch</code>).  Therefore it is set here as
68     chart dispatch.</p>
69  */
70 class CommandDispatchContainer
71 {
72 public:
73     // note: the chart dispatcher should be removed when all commands are
74     // handled by other dispatchers.  (Chart is currently the controller
75     // itself)
76     explicit CommandDispatchContainer(
77         const ::com::sun::star::uno::Reference<
78             ::com::sun::star::uno::XComponentContext > & xContext,
79         ChartController* pController );
80 
81     void setModel(
82         const ::com::sun::star::uno::Reference<
83             ::com::sun::star::frame::XModel > & xModel );
84 
85     /** Set a chart dispatcher that is used for all commands contained in
86         rChartCommands
87      */
88     void setChartDispatch(
89         const ::com::sun::star::uno::Reference<
90             ::com::sun::star::frame::XDispatch > xChartDispatch,
91         const ::std::set< ::rtl::OUString > & rChartCommands );
92 
93     /** Returns the dispatch that is able to do the command given in rURL, if
94         implemented here.  If the URL is not implemented here, it should be
95         checked whether the command is one of the commands given via
96         the setChartDispatch() method.  If so, call the chart dispatch.
97 
98         <p>If all this fails, return an empty dispatch.</p>
99      */
100     ::com::sun::star::uno::Reference<
101             ::com::sun::star::frame::XDispatch > getDispatchForURL(
102                 const ::com::sun::star::util::URL & rURL );
103 
104     ::com::sun::star::uno::Sequence<
105         ::com::sun::star::uno::Reference<
106             ::com::sun::star::frame::XDispatch > > getDispatchesForURLs(
107                 const ::com::sun::star::uno::Sequence<
108                     ::com::sun::star::frame::DispatchDescriptor > & aDescriptors );
109 
110     void DisposeAndClear();
111 
112     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >
113         getContainerDispatchForURL(
114             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > & xChartController,
115             const ::com::sun::star::util::URL & rURL );
116 
117     void setDrawCommandDispatch( DrawCommandDispatch* pDispatch );
getDrawCommandDispatch()118     DrawCommandDispatch* getDrawCommandDispatch() { return m_pDrawCommandDispatch; }
119     void setShapeController( ShapeController* pController );
getShapeController()120     ShapeController* getShapeController() { return m_pShapeController; }
121 
122 private:
123     typedef
124         ::std::map< ::rtl::OUString,
125             ::com::sun::star::uno::Reference<
126                 ::com::sun::star::frame::XDispatch > >
127         tDispatchMap;
128 
129     typedef
130         ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > tDisposeVector;
131 
132     mutable tDispatchMap m_aCachedDispatches;
133     mutable tDisposeVector m_aToBeDisposedDispatches;
134 
135     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >    m_xContext;
136     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel >         m_xModel;
137 
138     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > m_xChartDispatcher;
139     ::std::set< ::rtl::OUString >                                          m_aChartCommands;
140 
141     ::std::set< ::rtl::OUString >                                          m_aContainerDocumentCommands;
142 
143     ChartController* m_pChartController;
144     DrawCommandDispatch* m_pDrawCommandDispatch;
145     ShapeController* m_pShapeController;
146 };
147 
148 } //  namespace chart
149 
150 // CHART2_COMMANDDISPATCHCONTAINER_HXX
151 #endif
152