Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_FRAMESTATUSLISTENER_HXX
21 : #define INCLUDED_SVTOOLS_FRAMESTATUSLISTENER_HXX
22 :
23 : #include <svtools/svtdllapi.h>
24 : #include <com/sun/star/uno/XComponentContext.hpp>
25 : #include <com/sun/star/util/XURLTransformer.hpp>
26 : #include <com/sun/star/frame/XFrame.hpp>
27 : #include <com/sun/star/frame/XFrameActionListener.hpp>
28 : #include <com/sun/star/frame/XDispatch.hpp>
29 : #include <com/sun/star/frame/XStatusListener.hpp>
30 : #include <cppuhelper/weak.hxx>
31 : #include <cppuhelper/interfacecontainer.hxx>
32 : #include <comphelper/broadcasthelper.hxx>
33 :
34 : #include <unordered_map>
35 :
36 : namespace svt
37 : {
38 :
39 : class SVT_DLLPUBLIC FrameStatusListener : public ::com::sun::star::frame::XStatusListener,
40 : public ::com::sun::star::frame::XFrameActionListener,
41 : public ::com::sun::star::lang::XComponent,
42 : public ::comphelper::OBaseMutex,
43 : public ::cppu::OWeakObject
44 : {
45 : public:
46 : FrameStatusListener( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
47 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame );
48 : virtual ~FrameStatusListener();
49 :
50 : // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
51 : void addStatusListener( const OUString& aCommandURL );
52 : void bindListener();
53 : void unbindListener();
54 : bool isBound() const;
55 :
56 : // XInterface
57 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
58 : virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
59 : virtual void SAL_CALL release() throw () SAL_OVERRIDE;
60 :
61 : // XComponent
62 : virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
65 :
66 : // XEventListener
67 : virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
68 :
69 : // XStatusListener
70 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE = 0;
71 :
72 : // XFrameActionListener
73 : virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
74 :
75 : protected:
76 3708 : struct Listener
77 : {
78 1236 : Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
79 1236 : aURL( rURL ), xDispatch( rDispatch ) {}
80 :
81 : ::com::sun::star::util::URL aURL;
82 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
83 : };
84 :
85 : typedef std::unordered_map< OUString,
86 : css::uno::Reference< css::frame::XDispatch >,
87 : OUStringHash,
88 : std::equal_to< OUString > > URLToDispatchMap;
89 :
90 : bool m_bInitialized : 1,
91 : m_bDisposed : 1;
92 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
93 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
94 : URLToDispatchMap m_aListenerMap;
95 : };
96 :
97 : }
98 :
99 : #endif // INCLUDED_SVTOOLS_FRAMESTATUSLISTENER_HXX
100 :
101 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|