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          throw (::com::sun::star::uno::RuntimeException);
78  
79      // ____ WeakComponentImplHelperBase ____
80      /// is called when this is disposed
81      virtual void SAL_CALL disposing();
82  
83      // ____ XEventListener (base of XModifyListener) ____
84      virtual void SAL_CALL disposing(
85          const ::com::sun::star::lang::EventObject& Source )
86          throw (::com::sun::star::uno::RuntimeException);
87  
88      virtual void fireStatusEvent(
89          const ::rtl::OUString & rURL,
90          const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
91  
92      // ____ XModifyListener ____
93      virtual void SAL_CALL modified(
94          const ::com::sun::star::lang::EventObject& aEvent )
95          throw (::com::sun::star::uno::RuntimeException);
96  
97      // ____ XSelectionChangeListener ____
98      virtual void SAL_CALL selectionChanged(
99          const ::com::sun::star::lang::EventObject& aEvent )
100          throw (::com::sun::star::uno::RuntimeException);
101  
102  private:
103      void fireStatusEventForURLImpl(
104          const ::rtl::OUString & rURL,
105          const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
106  
107      bool commandAvailable( const ::rtl::OUString & rCommand );
108      void updateCommandAvailability();
109  
110      bool isShapeControllerCommandAvailable( const ::rtl::OUString& rCommand );
111  
112      ChartController* m_pChartController;
113      ::com::sun::star::uno::Reference<
114              ::com::sun::star::frame::XController > m_xController;
115      ::com::sun::star::uno::Reference<
116              ::com::sun::star::view::XSelectionSupplier > m_xSelectionSupplier;
117      ::com::sun::star::uno::Reference<
118              ::com::sun::star::frame::XDispatch > m_xDispatch;
119  
120      ::std::auto_ptr< impl::ModelState > m_apModelState;
121      ::std::auto_ptr< impl::ControllerState > m_apControllerState;
122  
123      mutable ::std::map< ::rtl::OUString, bool > m_aCommandAvailability;
124      mutable ::std::map< ::rtl::OUString, ::com::sun::star::uno::Any > m_aCommandArguments;
125  
126      CommandDispatchContainer* m_pDispatchContainer;
127  };
128  
129  } //  namespace chart
130  
131  // CHART2_CONTROLLERCOMMANDDISPATCH_HXX
132  #endif
133