xref: /AOO41X/main/chart2/source/controller/main/CommandDispatch.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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_COMMANDDISPATCH_HXX
28 #define CHART2_COMMANDDISPATCH_HXX
29 
30 #include "MutexContainer.hxx"
31 #include <cppuhelper/compbase2.hxx>
32 #include <com/sun/star/frame/XDispatch.hpp>
33 #include <com/sun/star/util/XModifyListener.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/util/XURLTransformer.hpp>
36 
37 #include <vector>
38 #include <map>
39 
40 namespace chart
41 {
42 
43 namespace impl
44 {
45 typedef ::cppu::WeakComponentImplHelper2<
46         ::com::sun::star::frame::XDispatch,
47         ::com::sun::star::util::XModifyListener >
48     CommandDispatch_Base;
49 }
50 
51 /** This is the base class for an XDispatch.
52  */
53 class CommandDispatch :
54         public MutexContainer,
55         public impl::CommandDispatch_Base
56 {
57 public:
58 	explicit CommandDispatch(
59         const ::com::sun::star::uno::Reference<
60             ::com::sun::star::uno::XComponentContext > & xContext );
61 	virtual ~CommandDispatch();
62 
63     // late initialisation, especially for adding as listener
64     virtual void initialize();
65 
66 protected:
67     /** sends a status event for a specific command to all registered listeners
68         or only the one given when set.
69 
70         This method should be overloaded.  The implementation should call
71         fireStatusEventForURL and pass the xSingleListener argument to this
72         method unchanged.
73 
74         @param rURL
75             If empty, all available status events must be fired, otherwise only
76             the one for the given command.
77 
78         @param xSingleListener
79             If set, the event is only sent to this listener rather than to all
80             registered ones.  Whenever a listener adds itself, this method is
81             called with this parameter set to give an initial state.
82      */
83     virtual void fireStatusEvent(
84         const ::rtl::OUString & rURL,
85         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener ) = 0;
86 
87     /** calls fireStatusEvent( ::rtl::OUString, xSingleListener )
88      */
89     void fireAllStatusEvents(
90         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener );
91 
92     /** sends a status event for a specific command to all registered listeners
93         or only the one given when set.
94 
95         @param xSingleListener
96             If set, the event is only sent to this listener rather than to all
97             registered ones.  Whenever a listener adds itself, this method is
98             called with this parameter set to give an initial state.
99      */
100     void fireStatusEventForURL(
101         const ::rtl::OUString & rURL,
102         const ::com::sun::star::uno::Any & rState,
103         bool bEnabled,
104         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener =
105             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >(),
106         const ::rtl::OUString & rFeatureDescriptor = ::rtl::OUString() );
107 
108     // ____ XDispatch ____
109     virtual void SAL_CALL dispatch(
110         const ::com::sun::star::util::URL& URL,
111         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments )
112         throw (::com::sun::star::uno::RuntimeException);
113     virtual void SAL_CALL addStatusListener(
114         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& Control,
115         const ::com::sun::star::util::URL& URL )
116         throw (::com::sun::star::uno::RuntimeException);
117     virtual void SAL_CALL removeStatusListener(
118         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& Control,
119         const ::com::sun::star::util::URL& URL )
120         throw (::com::sun::star::uno::RuntimeException);
121 
122     // ____ WeakComponentImplHelperBase ____
123     /// is called when this is disposed
124     virtual void SAL_CALL disposing();
125 
126     // ____ XModifyListener ____
127     virtual void SAL_CALL modified(
128         const ::com::sun::star::lang::EventObject& aEvent )
129         throw (::com::sun::star::uno::RuntimeException);
130 
131     // ____ XEventListener (base of XModifyListener) ____
132     virtual void SAL_CALL disposing(
133         const ::com::sun::star::lang::EventObject& Source )
134         throw (::com::sun::star::uno::RuntimeException);
135 
136 protected:
137     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
138     ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >  m_xURLTransformer;
139 
140 private:
141     typedef ::std::map< ::rtl::OUString, ::cppu::OInterfaceContainerHelper* >
142         tListenerMap;
143 
144     tListenerMap m_aListeners;
145 
146 };
147 
148 } //  namespace chart
149 
150 // CHART2_COMMANDDISPATCH_HXX
151 #endif
152