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