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 #ifndef _SVTOOLS_FRAMESTATUSLISTENER_HXX
25 #define _SVTOOLS_FRAMESTATUSLISTENER_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <com/sun/star/frame/XFrame.hpp>
31 #include <com/sun/star/frame/XFrameActionListener.hpp>
32 #include <com/sun/star/frame/XDispatch.hpp>
33 #include <com/sun/star/frame/XStatusListener.hpp>
34 #include <cppuhelper/weak.hxx>
35 #include <cppuhelper/interfacecontainer.hxx>
36 #include <comphelper/broadcasthelper.hxx>
37 
38 #ifndef INCLUDED_HASH_MAP
39 #include <hash_map>
40 #define INCLUDED_HASH_MAP
41 #endif
42 
43 namespace svt
44 {
45 
46 class SVT_DLLPUBLIC FrameStatusListener : public ::com::sun::star::frame::XStatusListener,
47                             public ::com::sun::star::frame::XFrameActionListener,
48                             public ::com::sun::star::lang::XComponent,
49                             public ::comphelper::OBaseMutex,
50                             public ::cppu::OWeakObject
51 {
52     public:
53         FrameStatusListener( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager,
54                              const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame );
55         virtual ~FrameStatusListener();
56 
57         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > getFrameInterface() const;
58         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getServiceManager() const;
59 
60         void updateStatus( const rtl::OUString aCommandURL );
61 
62         // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
63         void addStatusListener( const rtl::OUString& aCommandURL );
64         void removeStatusListener( const rtl::OUString& aCommandURL );
65         void bindListener();
66         void unbindListener();
67         sal_Bool isBound() const;
68 
69         // XInterface
70 		virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
71 		virtual void SAL_CALL acquire() throw ();
72 		virtual void SAL_CALL release() throw ();
73 
74         // XComponent
75         virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
76         virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
77         virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
78 
79         // XEventListener
80 		virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
81 
82         // XStatusListener
83 		virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ) = 0;
84 
85         // XFrameActionListener
86 		virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException );
87 
88     protected:
89         struct Listener
90         {
Listenersvt::FrameStatusListener::Listener91             Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
92                 aURL( rURL ), xDispatch( rDispatch ) {}
93 
94             ::com::sun::star::util::URL aURL;
95             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
96         };
97 
98         typedef ::std::hash_map< ::rtl::OUString,
99 				                 com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >,
100                                  ::rtl::OUStringHash,
101 								 ::std::equal_to< ::rtl::OUString > > URLToDispatchMap;
102 
103         sal_Bool                                                                            m_bInitialized : 1,
104                                                                                             m_bDisposed : 1;
105         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >                 m_xFrame;
106         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
107         URLToDispatchMap                                                                    m_aListenerMap;
108 };
109 
110 }
111 
112 #endif // _SVTOOLS_FRAMESTATUSLISTENER_HXX
113