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_FEATURECOMMANDDISPATCHBASE_HXX 24 #define CHART2_FEATURECOMMANDDISPATCHBASE_HXX 25 26 #include "CommandDispatch.hxx" 27 28 #include <com/sun/star/frame/CommandGroup.hpp> 29 #include <com/sun/star/frame/DispatchInformation.hpp> 30 #include <com/sun/star/util/URL.hpp> 31 32 namespace chart 33 { 34 35 struct ControllerFeature: public ::com::sun::star::frame::DispatchInformation 36 { 37 sal_uInt16 nFeatureId; 38 }; 39 40 typedef ::std::map< ::rtl::OUString, 41 ControllerFeature, 42 ::std::less< ::rtl::OUString > > SupportedFeatures; 43 44 struct FeatureState 45 { 46 bool bEnabled; 47 ::com::sun::star::uno::Any aState; 48 FeatureStatechart::FeatureState49 FeatureState() : bEnabled( false ) { } 50 }; 51 52 /** This is a base class for CommandDispatch implementations with feature support. 53 */ 54 class FeatureCommandDispatchBase: public CommandDispatch 55 { 56 public: 57 FeatureCommandDispatchBase( const ::com::sun::star::uno::Reference< 58 ::com::sun::star::uno::XComponentContext >& rxContext ); 59 virtual ~FeatureCommandDispatchBase(); 60 61 // late initialisation, especially for adding as listener 62 virtual void initialize(); 63 64 virtual bool isFeatureSupported( const ::rtl::OUString& rCommandURL ); 65 66 protected: 67 // XDispatch 68 virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& URL, 69 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) 70 throw (::com::sun::star::uno::RuntimeException); 71 72 virtual void fireStatusEvent( const ::rtl::OUString& rURL, 73 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xSingleListener ); 74 75 // state of a feature 76 virtual FeatureState getState( const ::rtl::OUString& rCommand ) = 0; 77 78 // execute a feature 79 virtual void execute( const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs ) = 0; 80 81 // all the features which should be handled by this class 82 virtual void describeSupportedFeatures() = 0; 83 84 /** describes a feature supported by the controller 85 86 Must not be called outside <member>describeSupportedFeatures</member>. 87 88 @param pAsciiCommandURL 89 the URL of the feature command 90 @param nId 91 the id of the feature. Later references to this feature usually happen by id, not by 92 URL. 93 @param nGroup 94 the command group of the feature. This is important for configuring the controller UI 95 by the user, see also <type scope="com::sun::star::frame">CommandGroup</type>. 96 */ 97 void implDescribeSupportedFeature( const sal_Char* pAsciiCommandURL, sal_uInt16 nId, 98 sal_Int16 nGroup = ::com::sun::star::frame::CommandGroup::INTERNAL ); 99 100 mutable SupportedFeatures m_aSupportedFeatures; 101 102 sal_uInt16 m_nFeatureId; 103 104 private: 105 void fillSupportedFeatures(); 106 }; 107 108 } // namespace chart 109 110 // CHART2_FEATURECOMMANDDISPATCHBASE_HXX 111 #endif 112