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 _SFXSTATUSLISTENER_HXX
25 #define _SFXSTATUSLISTENER_HXX
26 
27 #include "sal/config.h"
28 #include "sfx2/dllapi.h"
29 #include <svl/poolitem.hxx>
30 #include <cppuhelper/weak.hxx>
31 #include <osl/conditn.hxx>
32 #include <com/sun/star/frame/FeatureStateEvent.hpp>
33 #include <com/sun/star/frame/XDispatchProvider.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/frame/XStatusListener.hpp>
36 
37 #include <sfx2/sfxuno.hxx>
38 
39 // Interface for implementations which needs to get notifications about state changes
40 class SfxStatusListenerInterface
41 {
42     public:
43         virtual void StateChanged( sal_uInt16 nSlotId, SfxItemState eState, const SfxPoolItem* pState ) = 0;
44 };
45 
46 class SFX2_DLLPUBLIC SfxStatusListener :
47                           public ::com::sun::star::frame::XStatusListener	,
48 					      public ::com::sun::star::lang::XTypeProvider      ,
49                           public ::com::sun::star::lang::XComponent         ,
50 					      public ::cppu::OWeakObject
51 {
52     public:
53 	    SFX_DECL_XINTERFACE_XTYPEPROVIDER
54 
55         SfxStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider, sal_uInt16 nSlotId, const rtl::OUString& aCommand );
56         virtual ~SfxStatusListener();
57 
58         // old methods from SfxControllerItem
GetId() const59 	    sal_uInt16  GetId() const { return m_nSlotID; }
60 	    void    Bind();
61         void    Bind( sal_uInt16 nSlotID, const rtl::OUString& rNewCommand );
62 	    void    UnBind();
63 	    void    ReBind();
64 
65         virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
66 
67         // XComponent
68         virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );
69         virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
70         virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
71 
72         // XEventListener
73 	    virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
74 
75         // XStatusListener
76 	    virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
77 
78     private:
79         SfxStatusListener( const SfxStatusListener& );
80         SfxStatusListener();
81         SfxStatusListener& operator=( const SfxStatusListener& );
82 
83         sal_uInt16                                                                          m_nSlotID;
84         ::com::sun::star::util::URL                                                     m_aCommand;
85         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >  m_xDispatchProvider;
86         ::com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >            m_xDispatch;
87 };
88 
89 #endif // _SFXSTATUSLISTENER_HXX
90