1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef CHART2_CONTROLLERCOMMANDDISPATCH_HXX 28 #define CHART2_CONTROLLERCOMMANDDISPATCH_HXX 29 30 #include "CommandDispatch.hxx" 31 #include <com/sun/star/frame/XModel.hpp> 32 #include <com/sun/star/frame/XController.hpp> 33 #include <com/sun/star/view/XSelectionSupplier.hpp> 34 #include <cppuhelper/implbase1.hxx> 35 36 #include <memory> 37 38 namespace chart 39 { 40 41 class ChartController; 42 class CommandDispatchContainer; 43 44 namespace impl 45 { 46 struct ModelState; 47 struct ControllerState; 48 49 // #i63017# : need to implement the XSelectionChangeListener in order 50 // to update the ControllerState when the selection changes. 51 typedef ::cppu::ImplInheritanceHelper1< 52 CommandDispatch, 53 ::com::sun::star::view::XSelectionChangeListener > 54 ControllerCommandDispatch_Base; 55 } 56 57 /** This class is a CommandDispatch that is responsible for all commands that 58 the ChartController supports. 59 60 This class determines which commands are currently available (via the model 61 state) and if an available command is called forwards it to the 62 ChartController. 63 */ 64 class ControllerCommandDispatch : public impl::ControllerCommandDispatch_Base 65 { 66 public: 67 explicit ControllerCommandDispatch( 68 const ::com::sun::star::uno::Reference< 69 ::com::sun::star::uno::XComponentContext > & xContext, 70 ChartController* pController, CommandDispatchContainer* pContainer ); 71 virtual ~ControllerCommandDispatch(); 72 73 // late initialisation, especially for adding as listener 74 virtual void initialize(); 75 76 protected: 77 // ____ XDispatch ____ 78 virtual void SAL_CALL dispatch( 79 const ::com::sun::star::util::URL& URL, 80 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) 81 throw (::com::sun::star::uno::RuntimeException); 82 83 // ____ WeakComponentImplHelperBase ____ 84 /// is called when this is disposed 85 virtual void SAL_CALL disposing(); 86 87 // ____ XEventListener (base of XModifyListener) ____ 88 virtual void SAL_CALL disposing( 89 const ::com::sun::star::lang::EventObject& Source ) 90 throw (::com::sun::star::uno::RuntimeException); 91 92 virtual void fireStatusEvent( 93 const ::rtl::OUString & rURL, 94 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener ); 95 96 // ____ XModifyListener ____ 97 virtual void SAL_CALL modified( 98 const ::com::sun::star::lang::EventObject& aEvent ) 99 throw (::com::sun::star::uno::RuntimeException); 100 101 // ____ XSelectionChangeListener ____ 102 virtual void SAL_CALL selectionChanged( 103 const ::com::sun::star::lang::EventObject& aEvent ) 104 throw (::com::sun::star::uno::RuntimeException); 105 106 private: 107 void fireStatusEventForURLImpl( 108 const ::rtl::OUString & rURL, 109 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener ); 110 111 bool commandAvailable( const ::rtl::OUString & rCommand ); 112 void updateCommandAvailability(); 113 114 bool isShapeControllerCommandAvailable( const ::rtl::OUString& rCommand ); 115 116 ChartController* m_pChartController; 117 ::com::sun::star::uno::Reference< 118 ::com::sun::star::frame::XController > m_xController; 119 ::com::sun::star::uno::Reference< 120 ::com::sun::star::view::XSelectionSupplier > m_xSelectionSupplier; 121 ::com::sun::star::uno::Reference< 122 ::com::sun::star::frame::XDispatch > m_xDispatch; 123 124 ::std::auto_ptr< impl::ModelState > m_apModelState; 125 ::std::auto_ptr< impl::ControllerState > m_apControllerState; 126 127 mutable ::std::map< ::rtl::OUString, bool > m_aCommandAvailability; 128 mutable ::std::map< ::rtl::OUString, ::com::sun::star::uno::Any > m_aCommandArguments; 129 130 CommandDispatchContainer* m_pDispatchContainer; 131 }; 132 133 } // namespace chart 134 135 // CHART2_CONTROLLERCOMMANDDISPATCH_HXX 136 #endif 137