xref: /trunk/main/chart2/source/controller/main/ControllerCommandDispatch.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_CONTROLLERCOMMANDDISPATCH_HXX
24 #define CHART2_CONTROLLERCOMMANDDISPATCH_HXX
25 
26 #include "CommandDispatch.hxx"
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/frame/XController.hpp>
29 #include <com/sun/star/view/XSelectionSupplier.hpp>
30 #include <cppuhelper/implbase1.hxx>
31 
32 #include <memory>
33 
34 namespace chart
35 {
36 
37 class ChartController;
38 class CommandDispatchContainer;
39 
40 namespace impl
41 {
42 struct ModelState;
43 struct ControllerState;
44 
45 // #i63017# : need to implement the XSelectionChangeListener in order
46 // to update the ControllerState when the selection changes.
47 typedef ::cppu::ImplInheritanceHelper1<
48         CommandDispatch,
49         ::com::sun::star::view::XSelectionChangeListener >
50     ControllerCommandDispatch_Base;
51 }
52 
53 /** This class is a CommandDispatch that is responsible for all commands that
54     the ChartController supports.
55 
56     This class determines which commands are currently available (via the model
57     state) and if an available command is called forwards it to the
58     ChartController.
59  */
60 class ControllerCommandDispatch : public impl::ControllerCommandDispatch_Base
61 {
62 public:
63     explicit ControllerCommandDispatch(
64         const ::com::sun::star::uno::Reference<
65             ::com::sun::star::uno::XComponentContext > & xContext,
66         ChartController* pController, CommandDispatchContainer* pContainer );
67     virtual ~ControllerCommandDispatch();
68 
69     // late initialisation, especially for adding as listener
70     virtual void initialize();
71 
72 protected:
73     // ____ XDispatch ____
74     virtual void SAL_CALL dispatch(
75         const ::com::sun::star::util::URL& URL,
76         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments );
77 
78     // ____ WeakComponentImplHelperBase ____
79     /// is called when this is disposed
80     virtual void SAL_CALL disposing();
81 
82     // ____ XEventListener (base of XModifyListener) ____
83     virtual void SAL_CALL disposing(
84         const ::com::sun::star::lang::EventObject& Source );
85 
86     virtual void fireStatusEvent(
87         const ::rtl::OUString & rURL,
88         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
89 
90     // ____ XModifyListener ____
91     virtual void SAL_CALL modified(
92         const ::com::sun::star::lang::EventObject& aEvent );
93 
94     // ____ XSelectionChangeListener ____
95     virtual void SAL_CALL selectionChanged(
96         const ::com::sun::star::lang::EventObject& aEvent );
97 
98 private:
99     void fireStatusEventForURLImpl(
100         const ::rtl::OUString & rURL,
101         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
102 
103     bool commandAvailable( const ::rtl::OUString & rCommand );
104     void updateCommandAvailability();
105 
106     bool isShapeControllerCommandAvailable( const ::rtl::OUString& rCommand );
107 
108     ChartController* m_pChartController;
109     ::com::sun::star::uno::Reference<
110             ::com::sun::star::frame::XController > m_xController;
111     ::com::sun::star::uno::Reference<
112             ::com::sun::star::view::XSelectionSupplier > m_xSelectionSupplier;
113     ::com::sun::star::uno::Reference<
114             ::com::sun::star::frame::XDispatch > m_xDispatch;
115 
116     ::std::auto_ptr< impl::ModelState > m_apModelState;
117     ::std::auto_ptr< impl::ControllerState > m_apControllerState;
118 
119     mutable ::std::map< ::rtl::OUString, bool > m_aCommandAvailability;
120     mutable ::std::map< ::rtl::OUString, ::com::sun::star::uno::Any > m_aCommandArguments;
121 
122     CommandDispatchContainer* m_pDispatchContainer;
123 };
124 
125 } //  namespace chart
126 
127 // CHART2_CONTROLLERCOMMANDDISPATCH_HXX
128 #endif
129