calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / inc / vclstatuslistener.hxx
blob2335a66e73430c9725d46221665a9ce894e13965
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef INCLUDED_VCL_VCLSTATUSLISTENER_HXX
11 #define INCLUDED_VCL_VCLSTATUSLISTENER_HXX
13 #include <cppuhelper/implbase.hxx>
14 #include <comphelper/processfactory.hxx>
15 #include <vcl/vclptr.hxx>
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <com/sun/star/frame/XStatusListener.hpp>
19 #include <com/sun/star/frame/XDispatch.hpp>
20 #include <com/sun/star/frame/XDispatchProvider.hpp>
21 #include <com/sun/star/util/URL.hpp>
22 #include <com/sun/star/util/URLTransformer.hpp>
24 template <class T> class VclStatusListener final : public cppu::WeakImplHelper < css::frame::XStatusListener>
26 public:
27 VclStatusListener(T* widget, const css::uno::Reference<css::frame::XFrame>& rFrame, const OUString& aCommand);
29 private:
30 VclPtr<T> mWidget; /** The widget on which actions are performed */
32 /** Dispatcher. Need to keep a reference to it as long as this StatusListener exists. */
33 css::uno::Reference<css::frame::XDispatch> mxDispatch;
34 css::util::URL maCommandURL;
35 css::uno::Reference<css::frame::XFrame> mxFrame;
37 public:
38 void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override;
40 void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) override;
42 void startListening();
44 void dispose();
47 template<class T>
48 VclStatusListener<T>::VclStatusListener(T* widget, const css::uno::Reference<css::frame::XFrame>& rFrame, const OUString& aCommand) :
49 mWidget(widget),
50 mxFrame(rFrame)
52 css::uno::Reference<css::uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
53 maCommandURL.Complete = aCommand;
54 css::uno::Reference<css::util::XURLTransformer> xParser = css::util::URLTransformer::create(xContext);
55 xParser->parseStrict(maCommandURL);
58 template<class T>
59 void VclStatusListener<T>::startListening()
61 css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(mxFrame, css::uno::UNO_QUERY);
62 if (!xDispatchProvider.is())
63 return;
65 mxDispatch = xDispatchProvider->queryDispatch(maCommandURL, "", 0);
66 if (mxDispatch.is())
67 mxDispatch->addStatusListener(this, maCommandURL);
70 template<class T>
71 void VclStatusListener<T>::statusChanged(const css::frame::FeatureStateEvent& rEvent)
73 mWidget->statusChanged(rEvent);
76 template<class T>
77 void VclStatusListener<T>::disposing(const css::lang::EventObject& /*Source*/)
79 mxDispatch.clear();
82 template<class T>
83 void VclStatusListener<T>::dispose()
85 if (mxDispatch.is()) {
86 mxDispatch->removeStatusListener(this, maCommandURL);
87 mxDispatch.clear();
89 mxFrame.clear();
90 mWidget.clear();
94 #endif // INCLUDED_VCL_VCLSTATUSLISTENER_HXX
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */