diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2015-12-04 16:28:27 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2015-12-07 11:29:42 +0000 |
commit | c5fe98905deac6de4f9e76a17097ce83fe381ac3 (patch) | |
tree | 06fd82303f00a8e64e0498c817944b98fc2ec36d /include/vcl | |
parent | ebe80ac6713b67b1801ede3d1e9038cb2c93cb11 (diff) |
Make buttonstatuslistener a generic listener for any widgets
Change-Id: I966b06e1169f8a06d08be811f78e98a2e3d7580c
Reviewed-on: https://gerrit.libreoffice.org/20401
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'include/vcl')
-rw-r--r-- | include/vcl/button.hxx | 4 | ||||
-rw-r--r-- | include/vcl/buttonstatuslistener.hxx | 45 | ||||
-rw-r--r-- | include/vcl/vclstatuslistener.hxx | 100 |
3 files changed, 102 insertions, 47 deletions
diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx index 93d5b99e8b03..81c79a2b1de8 100644 --- a/include/vcl/button.hxx +++ b/include/vcl/button.hxx @@ -94,7 +94,7 @@ public: virtual bool set_property(const OString &rKey, const OString &rValue) override; /// Sets the button state according to the FeatureStateEvent emitted by an Uno state change. - virtual void SetStateUno(const css::frame::FeatureStateEvent& rEvent); + void statusChanged(const css::frame::FeatureStateEvent& rEvent); protected: @@ -187,7 +187,7 @@ public: void SetState( TriState eState ); TriState GetState() const { return meState; } - virtual void SetStateUno(const css::frame::FeatureStateEvent& rEvent) override; + void statusChanged(const css::frame::FeatureStateEvent& rEvent); void Check( bool bCheck = true ); bool IsChecked() const; diff --git a/include/vcl/buttonstatuslistener.hxx b/include/vcl/buttonstatuslistener.hxx deleted file mode 100644 index 772189591114..000000000000 --- a/include/vcl/buttonstatuslistener.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef INCLUDED_VCL_BUTTONSTATUSLISTENER_HXX -#define INCLUDED_VCL_BUTTONSTATUSLISTENER_HXX - -#include <cppuhelper/implbase.hxx> -#include <vcl/button.hxx> - -#include <com/sun/star/util/URL.hpp> -#include <com/sun/star/frame/XStatusListener.hpp> -#include <com/sun/star/frame/XDispatch.hpp> - - -class VCL_DLLPUBLIC ButtonStatusListener : public cppu::WeakImplHelper < css::frame::XStatusListener> -{ -public: - ButtonStatusListener(Button* button, const rtl::OUString& aCommand); - -private: - VclPtr<Button> mButton; /** The button on which actions are performed */ - - /** Dispatcher. Need to keep a reference to it as long as this StatusListener exists. */ - css::uno::Reference<css::frame::XDispatch> mxDispatch; - css::util::URL maCommandURL; - -public: - virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) - throw(css::uno::RuntimeException, std::exception) override; - - virtual void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) - throw( css::uno::RuntimeException, std::exception ) override; - - void dispose(); -}; - -#endif // INCLUDED_VCL_BUTTONSTATUSLISTENER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/include/vcl/vclstatuslistener.hxx b/include/vcl/vclstatuslistener.hxx new file mode 100644 index 000000000000..186d4491406d --- /dev/null +++ b/include/vcl/vclstatuslistener.hxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_VCL_VCLSTATUSLISTENER_HXX +#define INCLUDED_VCL_VCLSTATUSLISTENER_HXX + +#include <cppuhelper/implbase.hxx> +#include <comphelper/processfactory.hxx> +#include <vcl/dllapi.h> +#include <vcl/vclptr.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/util/URL.hpp> +#include <com/sun/star/util/URLTransformer.hpp> + +template <class T> class VCL_DLLPUBLIC VclStatusListener : public cppu::WeakImplHelper < css::frame::XStatusListener> +{ +public: + VclStatusListener<T>(T* widget, const rtl::OUString& aCommand); + +private: + VclPtr<T> mWidget; /** The widget on which actions are performed */ + + /** Dispatcher. Need to keep a reference to it as long as this StatusListener exists. */ + css::uno::Reference<css::frame::XDispatch> mxDispatch; + css::util::URL maCommandURL; + +public: + void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) + throw(css::uno::RuntimeException, std::exception) override; + + void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) + throw( css::uno::RuntimeException, std::exception ) override; + + void dispose(); +}; + +template<class T> +VclStatusListener<T>::VclStatusListener(T* widget, const rtl::OUString& aCommand) { + mWidget = widget; + + css::uno::Reference<css::uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); + css::uno::Reference<css::frame::XDesktop2> xDesktop = css::frame::Desktop::create(xContext); + + css::uno::Reference<css::frame::XFrame> xFrame(xDesktop->getActiveFrame()); + if (!xFrame.is()) + xFrame = css::uno::Reference<css::frame::XFrame>(xDesktop, css::uno::UNO_QUERY); + + css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(xFrame, css::uno::UNO_QUERY); + if (!xDispatchProvider.is()) + return; + + maCommandURL.Complete = aCommand; + css::uno::Reference<css::util::XURLTransformer> xParser = css::util::URLTransformer::create(xContext); + xParser->parseStrict(maCommandURL); + + mxDispatch = xDispatchProvider->queryDispatch(maCommandURL, "", 0); + if (!mxDispatch.is()) + return; + + mxDispatch->addStatusListener(this, maCommandURL); +} + +template<class T> +void VclStatusListener<T>::statusChanged(const css::frame::FeatureStateEvent& rEvent) + throw(css::uno::RuntimeException, std::exception) +{ + mWidget->statusChanged(rEvent); +} + +template<class T> +void VclStatusListener<T>::disposing(const css::lang::EventObject& /*Source*/) + throw( css::uno::RuntimeException, std::exception ) +{ + mxDispatch.clear(); +} + +template<class T> +void VclStatusListener<T>::dispose() +{ + if (mxDispatch.is()) { + mxDispatch->removeStatusListener(this, maCommandURL); + mxDispatch.clear(); + } + mWidget.clear(); +} + + +#endif // INCLUDED_VCL_VCLSTATUSLISTENER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file |