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 71 virtual void fireStatusEvent( const ::rtl::OUString& rURL, 72 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xSingleListener ); 73 74 // state of a feature 75 virtual FeatureState getState( const ::rtl::OUString& rCommand ) = 0; 76 77 // execute a feature 78 virtual void execute( const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs ) = 0; 79 80 // all the features which should be handled by this class 81 virtual void describeSupportedFeatures() = 0; 82 83 /** describes a feature supported by the controller 84 85 Must not be called outside <member>describeSupportedFeatures</member>. 86 87 @param pAsciiCommandURL 88 the URL of the feature command 89 @param nId 90 the id of the feature. Later references to this feature usually happen by id, not by 91 URL. 92 @param nGroup 93 the command group of the feature. This is important for configuring the controller UI 94 by the user, see also <type scope="com::sun::star::frame">CommandGroup</type>. 95 */ 96 void implDescribeSupportedFeature( const sal_Char* pAsciiCommandURL, sal_uInt16 nId, 97 sal_Int16 nGroup = ::com::sun::star::frame::CommandGroup::INTERNAL ); 98 99 mutable SupportedFeatures m_aSupportedFeatures; 100 101 sal_uInt16 m_nFeatureId; 102 103 private: 104 void fillSupportedFeatures(); 105 }; 106 107 } // namespace chart 108 109 // CHART2_FEATURECOMMANDDISPATCHBASE_HXX 110 #endif 111