1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*de7b3f82SAndrew Rist  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*de7b3f82SAndrew Rist  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19*de7b3f82SAndrew Rist  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew Rist 
23cdf0e10cSrcweir #ifndef CHART2_CONTROLLERCOMMANDDISPATCH_HXX
24cdf0e10cSrcweir #define CHART2_CONTROLLERCOMMANDDISPATCH_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "CommandDispatch.hxx"
27cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
28cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
29cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <memory>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace chart
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class ChartController;
38cdf0e10cSrcweir class CommandDispatchContainer;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace impl
41cdf0e10cSrcweir {
42cdf0e10cSrcweir struct ModelState;
43cdf0e10cSrcweir struct ControllerState;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // #i63017# : need to implement the XSelectionChangeListener in order
46cdf0e10cSrcweir // to update the ControllerState when the selection changes.
47cdf0e10cSrcweir typedef ::cppu::ImplInheritanceHelper1<
48cdf0e10cSrcweir         CommandDispatch,
49cdf0e10cSrcweir         ::com::sun::star::view::XSelectionChangeListener >
50cdf0e10cSrcweir     ControllerCommandDispatch_Base;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /** This class is a CommandDispatch that is responsible for all commands that
54cdf0e10cSrcweir     the ChartController supports.
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     This class determines which commands are currently available (via the model
57cdf0e10cSrcweir     state) and if an available command is called forwards it to the
58cdf0e10cSrcweir     ChartController.
59cdf0e10cSrcweir  */
60cdf0e10cSrcweir class ControllerCommandDispatch : public impl::ControllerCommandDispatch_Base
61cdf0e10cSrcweir {
62cdf0e10cSrcweir public:
63cdf0e10cSrcweir     explicit ControllerCommandDispatch(
64cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
65cdf0e10cSrcweir             ::com::sun::star::uno::XComponentContext > & xContext,
66cdf0e10cSrcweir         ChartController* pController, CommandDispatchContainer* pContainer );
67cdf0e10cSrcweir     virtual ~ControllerCommandDispatch();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // late initialisation, especially for adding as listener
70cdf0e10cSrcweir     virtual void initialize();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir protected:
73cdf0e10cSrcweir     // ____ XDispatch ____
74cdf0e10cSrcweir     virtual void SAL_CALL dispatch(
75cdf0e10cSrcweir         const ::com::sun::star::util::URL& URL,
76cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments )
77cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // ____ WeakComponentImplHelperBase ____
80cdf0e10cSrcweir     /// is called when this is disposed
81cdf0e10cSrcweir     virtual void SAL_CALL disposing();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     // ____ XEventListener (base of XModifyListener) ____
84cdf0e10cSrcweir     virtual void SAL_CALL disposing(
85cdf0e10cSrcweir         const ::com::sun::star::lang::EventObject& Source )
86cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     virtual void fireStatusEvent(
89cdf0e10cSrcweir         const ::rtl::OUString & rURL,
90cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     // ____ XModifyListener ____
93cdf0e10cSrcweir     virtual void SAL_CALL modified(
94cdf0e10cSrcweir         const ::com::sun::star::lang::EventObject& aEvent )
95cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // ____ XSelectionChangeListener ____
98cdf0e10cSrcweir     virtual void SAL_CALL selectionChanged(
99cdf0e10cSrcweir         const ::com::sun::star::lang::EventObject& aEvent )
100cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir private:
103cdf0e10cSrcweir     void fireStatusEventForURLImpl(
104cdf0e10cSrcweir         const ::rtl::OUString & rURL,
105cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     bool commandAvailable( const ::rtl::OUString & rCommand );
108cdf0e10cSrcweir     void updateCommandAvailability();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     bool isShapeControllerCommandAvailable( const ::rtl::OUString& rCommand );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     ChartController* m_pChartController;
113cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
114cdf0e10cSrcweir             ::com::sun::star::frame::XController > m_xController;
115cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
116cdf0e10cSrcweir             ::com::sun::star::view::XSelectionSupplier > m_xSelectionSupplier;
117cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
118cdf0e10cSrcweir             ::com::sun::star::frame::XDispatch > m_xDispatch;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     ::std::auto_ptr< impl::ModelState > m_apModelState;
121cdf0e10cSrcweir     ::std::auto_ptr< impl::ControllerState > m_apControllerState;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     mutable ::std::map< ::rtl::OUString, bool > m_aCommandAvailability;
124cdf0e10cSrcweir     mutable ::std::map< ::rtl::OUString, ::com::sun::star::uno::Any > m_aCommandArguments;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     CommandDispatchContainer* m_pDispatchContainer;
127cdf0e10cSrcweir };
128cdf0e10cSrcweir 
129cdf0e10cSrcweir } //  namespace chart
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // CHART2_CONTROLLERCOMMANDDISPATCH_HXX
132cdf0e10cSrcweir #endif
133