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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "FeatureCommandDispatchBase.hxx"
28 
29 using namespace ::com::sun::star;
30 
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33 
34 namespace chart
35 {
36 
FeatureCommandDispatchBase(const Reference<uno::XComponentContext> & rxContext)37 FeatureCommandDispatchBase::FeatureCommandDispatchBase( const Reference< uno::XComponentContext >& rxContext )
38     :CommandDispatch( rxContext )
39     ,m_nFeatureId( 0 )
40 {
41 }
42 
~FeatureCommandDispatchBase()43 FeatureCommandDispatchBase::~FeatureCommandDispatchBase()
44 {
45 }
46 
initialize()47 void FeatureCommandDispatchBase::initialize()
48 {
49     CommandDispatch::initialize();
50     fillSupportedFeatures();
51 }
52 
isFeatureSupported(const::rtl::OUString & rCommandURL)53 bool FeatureCommandDispatchBase::isFeatureSupported( const ::rtl::OUString& rCommandURL )
54 {
55     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( rCommandURL );
56     if ( aIter != m_aSupportedFeatures.end() )
57     {
58         return true;
59     }
60     return false;
61 }
62 
fireStatusEvent(const::rtl::OUString & rURL,const Reference<frame::XStatusListener> & xSingleListener)63 void FeatureCommandDispatchBase::fireStatusEvent( const ::rtl::OUString& rURL,
64     const Reference< frame::XStatusListener >& xSingleListener /* = 0 */ )
65 {
66     if ( rURL.isEmpty() )
67     {
68         SupportedFeatures::const_iterator aEnd( m_aSupportedFeatures.end() );
69         for ( SupportedFeatures::const_iterator aIter( m_aSupportedFeatures.begin() ); aIter != aEnd; ++aIter )
70         {
71             FeatureState aFeatureState( getState( aIter->first ) );
72             fireStatusEventForURL( aIter->first, aFeatureState.aState, aFeatureState.bEnabled, xSingleListener );
73         }
74     }
75     else
76     {
77         FeatureState aFeatureState( getState( rURL ) );
78         fireStatusEventForURL( rURL, aFeatureState.aState, aFeatureState.bEnabled, xSingleListener );
79     }
80 }
81 
82 // XDispatch
dispatch(const util::URL & URL,const Sequence<beans::PropertyValue> & Arguments)83 void FeatureCommandDispatchBase::dispatch( const util::URL& URL,
84     const Sequence< beans::PropertyValue >& Arguments )
85     throw (uno::RuntimeException)
86 {
87     ::rtl::OUString aCommand( URL.Complete );
88     if ( getState( aCommand ).bEnabled )
89     {
90         execute( aCommand, Arguments );
91     }
92 }
93 
implDescribeSupportedFeature(const sal_Char * pAsciiCommandURL,sal_uInt16 nId,sal_Int16 nGroup)94 void FeatureCommandDispatchBase::implDescribeSupportedFeature( const sal_Char* pAsciiCommandURL,
95     sal_uInt16 nId, sal_Int16 nGroup )
96 {
97     ControllerFeature aFeature;
98     aFeature.Command = ::rtl::OUString::createFromAscii( pAsciiCommandURL );
99     aFeature.nFeatureId = nId;
100     aFeature.GroupId = nGroup;
101 
102     m_aSupportedFeatures[ aFeature.Command ] = aFeature;
103 }
104 
fillSupportedFeatures()105 void FeatureCommandDispatchBase::fillSupportedFeatures()
106 {
107     describeSupportedFeatures();
108 }
109 
110 } //  namespace chart
111