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